System.Object
System.MarshalByRefObject
System.ComponentModel.Component
System.Windows.Forms.Control
System.Windows.Forms.ButtonBase
System.Windows.Forms.CheckBox
public class CheckBox : ButtonBase
このクラスのコンストラクタは、デフォルトコンストラクタしかありませんusing System.Windows.Forms;
using System.Drawing;
class WinMain : Form {
public static void Main(string[] args) {
Application.Run(new WinMain());
}
public WinMain() {
CheckBox bt = new CheckBox();
bt.Size = new Size(200 , 30);
bt.Text = "Kitty on your lap";
Controls.Add(bt);
}
}

using System.Windows.Forms;
using System.Drawing;
class WinMain : Form {
public static void Main(string[] args) {
Application.Run(new WinMain());
}
public WinMain() {
CheckBox bt = new CheckBox();
bt.Size = new Size(200 , 30);
bt.Text = "Kitty on your lap";
Controls.Add(bt);
}
override protected void OnMouseUp(MouseEventArgs e) {
CheckBox bt = (CheckBox)Controls[0];
MessageBox.Show("チェック状態は" + bt.Checked + "です");
}
}
このプログラムは、ウィンドウのクライアント領域をクリックすると[Serializable] public enum CheckStateこの列挙型は、次のようなメンバを定義しています
| メンバ | 解説 |
|---|---|
| Checked | コントロールがチェックされています |
| Indeterminate | コントロールが不確定状態になっています 不確定状態のコントロールは、通常、網かけ表示されます |
| Unchecked | コントロールがチェックされていません |
using System.Windows.Forms;
using System.Drawing;
class WinMain : Form {
public static void Main(string[] args) {
Application.Run(new WinMain());
}
public WinMain() {
CheckBox bt = new CheckBox();
bt.Size = new Size(200 , 30);
bt.Text = "Kitty on your lap";
bt.ThreeState = true;
Controls.Add(bt);
}
}
