CheckBox クラスの新しいインスタンスを初期化します。
名前空間: System.Web.UI.WebControls
アセンブリ: System.Web (system.web.dll 内)
構文
'宣言
Public Sub New
'使用
Dim instance As New CheckBox
public CheckBox ()
public:
CheckBox ()
public CheckBox ()
public function CheckBox ()
適用できません。
解説
このコンストラクタを使用して、CheckBox クラスの新しいインスタンスを作成し、初期化します。
使用例
![]() |
---|
次のコード サンプルはシングルファイル コード モデルを使用しており、分離コード ファイルに直接コピーされた場合は正常に動作しない可能性があります。このコード サンプルは、拡張子が .aspx の空のテキスト ファイルにコピーする必要があります。Web フォームのコード モデルの詳細については、「ASP.NET Web ページのコード モデル」を参照してください。 |
<%@ Page Language="VB" AutoEventWireup="True" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title> CheckBox Constructor Example </title>
<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 id="form1" 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" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title> CheckBox Constructor Example </title>
<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 id="form1" 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 Server 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
Microsoft .NET Framework 3.0 は Windows Vista,Microsoft Windows XP SP2,および Windows Server 2003 SP1 でサポートされています。
バージョン情報
.NET Framework
サポート対象 : 3.0,2.0,1.1,1.0