本文整理汇总了C#中System.Windows.Forms.CheckBox类的典型用法代码示例。如果您正苦于以下问题:C# CheckBox类的具体用法?C# CheckBox怎么用?C# CheckBox使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
CheckBox类属于System.Windows.Forms命名空间,在下文中一共展示了CheckBox类的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: InstantiateMyCheckBox
public void InstantiateMyCheckBox()
{
// Create and initialize a CheckBox.
CheckBox checkBox1 = new CheckBox();
// Make the check box control appear as a toggle button.
checkBox1.Appearance = Appearance.Button;
// Turn off the update of the display on the click of the control.
checkBox1.AutoCheck = false;
// Add the check box control to the form.
Controls.Add(checkBox1);
}
示例2: new CheckBox()
//引入命名空间
using System;
using System.Drawing;
using System.Windows.Forms;
class CheckBoxWithLabel: Form
{
Label label;
FontStyle fs = 0;
FontStyle[] afs = { FontStyle.Bold,FontStyle.Italic, FontStyle.Underline, FontStyle.Strikeout };
public static void Main()
{
Application.Run(new CheckBoxWithLabel());
}
public CheckBoxWithLabel()
{
int cyText = Font.Height;
int cxText = cyText / 2;
string[] astrText = {"Bold", "Italic", "Underline", "Strikeout"};
label = new Label();
label.Parent = this;
label.Text = "Sample Text";
label.AutoSize = true;
for (int i = 0; i < 4; i++)
{
CheckBox chkbox = new CheckBox();
chkbox.Parent = this;
chkbox.Text = astrText[i];
chkbox.Location = new Point(2 * cxText, (4 + 3 * i) * cyText / 2);
chkbox.Size = new Size(12 * cxText, cyText);
chkbox.CheckedChanged += new EventHandler(CheckBoxOnCheckedChanged);
}
}
void CheckBoxOnCheckedChanged(object obj, EventArgs ea)
{
for (int i = 0; i < 4; i++)
if (((CheckBox) Controls[i + 1]).Checked)
fs |= afs[i];
label.Font = new Font(label.Font, fs);
}
}