CheckBox コンストラクタ
アセンブリ: System.Web (system.web.dll 内)



![]() |
---|
次のコード サンプルはシングルファイル コード モデルを使用しており、分離コード ファイルに直接コピーされた場合は正常に動作しない可能性があります。このコード サンプルは、拡張子が .aspx の空のテキスト ファイルにコピーする必要があります。Web フォームのコード モデルの詳細については、「ASP.NET Web ページのコード モデル」を参照してください。 |
<%@ Page Language="VB" AutoEventWireup="True" %> <html> <head> <script runat="server"> Sub Page_Load(sender As Object, e As EventArgs) ' Create new CheckBox control. Dim NewCheckBox As CheckBox = New CheckBox() NewCheckBox.ID="FeatureCheckBox" NewCheckBox.Text="Enable feature" NewCheckBox.AutoPostBack = True ' Register the event handling method for the CheckedChanged event. AddHandler NewCheckBox.CheckedChanged, AddressOf Check_Change ' Add the control to the Controls collection of the ' PlaceHolder control. Place.Controls.Clear() Place.Controls.Add(NewCheckBox) End Sub Sub Check_Change(sender As Object, e As EventArgs) ' Retrieve the CheckBox control from the PlaceHolder control. Dim check As CheckBox = _ CType(Place.FindControl("FeatureCheckBox"), CheckBox) ' Display the appropriate message based on the state of the ' CheckBox control. If check.Checked Then Message.Text = "Feature enabled." Else Message.Text = "Feature disabled." End If End Sub </script> </head> <body> <form runat="server"> <h3> CheckBox Constructor Example </h3> Click the check box. <br><br> <asp:Placeholder id="Place" runat="server"/> <br><br> <asp:Label id="Message" runat="server"/> </form> </body> </html>
<%@ Page Language="C#" AutoEventWireup="True" %> <html> <head> <script runat="server"> void Page_Load(Object sender, EventArgs e) { // Create new CheckBox control. CheckBox NewCheckBox = new CheckBox(); NewCheckBox.ID="FeatureCheckBox"; NewCheckBox.Text="Enable feature"; NewCheckBox.AutoPostBack = true; // Register the event-handling method for the CheckedChanged event. NewCheckBox.CheckedChanged += new EventHandler(this.Check_Change); // Add the control to the Controls collection of the // PlaceHolder control. Place.Controls.Clear(); Place.Controls.Add(NewCheckBox); } void Check_Change(Object sender, EventArgs e) { // Retrieve the CheckBox control from the PlaceHolder control. CheckBox check = (CheckBox)Place.FindControl("FeatureCheckBox"); // Display the appropriate message based on the state of the // CheckBox control. if(check.Checked) { Message.Text = "Feature enabled."; } else { Message.Text = "Feature disabled."; } } </script> </head> <body> <form runat="server"> <h3> CheckBox Constructor Example </h3> Click the check box. <br><br> <asp:Placeholder id="Place" runat="server"/> <br><br> <asp:Label id="Message" runat="server"/> </form> </body> </html>

Windows 98, Windows 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


CheckBox コンストラクタ
アセンブリ: System.Windows.Forms (system.windows.forms.dll 内)


既定では、新しい CheckBox がインスタンス化されると、AutoCheck が true に、Checked が false に、Appearance が Normal に、それぞれ設定されます。

CheckBox を作成および初期化し、その外観をトグル ボタンにするコード例を次に示します。さらに、AutoCheck を false に設定し、トグル ボタンを Form に追加します。
Public Sub InstantiateMyCheckBox() ' Create and initialize a CheckBox. Dim checkBox1 As 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) End Sub '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); }
public: void InstantiateMyCheckBox() { // Create and initialize a CheckBox. CheckBox^ checkBox1 = gcnew 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. this->Controls->Add( checkBox1 ); }
public void InstantiateMyCheckBox() { // Create and initialize a CheckBox. CheckBox checkBox1 = new CheckBox(); // Make the check box control appear as a toggle button. checkBox1.set_Appearance(Appearance.Button); // Turn off the update of the display on the click of the control. checkBox1.set_AutoCheck(false); // Add the check box control to the form. get_Controls().Add(checkBox1); } //InstantiateMyCheckBox
public function InstantiateMyCheckBox() { // Create and initialize a CheckBox. var checkBox1 : CheckBox = 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); }

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


Weblioに収録されているすべての辞書からCheckBox コンストラクタを検索する場合は、下記のリンクをクリックしてください。

- CheckBox コンストラクタのページへのリンク