CheckBox.Checked プロパティ
アセンブリ: System.Web (system.web.dll 内)

<BindableAttribute(True, BindingDirection.TwoWay)> _ <ThemeableAttribute(False)> _ Public Overridable Property Checked As Boolean
[BindableAttribute(true, BindingDirection.TwoWay)] [ThemeableAttribute(false)] public virtual bool Checked { get; set; }
[BindableAttribute(true, BindingDirection::TwoWay)] [ThemeableAttribute(false)] public: virtual property bool Checked { bool get (); void set (bool value); }
/** @property */ public boolean get_Checked () /** @property */ public void set_Checked (boolean value)
チェックされた状態の場合は true。それ以外の場合は false。既定値は false です。

このプロパティを使用して、CheckBox コントロールがチェックされているかどうかを確認します。このプロパティは、CheckBox コントロールの状態をプログラムにより設定するときにも使用できます。
このプロパティを、テーマまたはスタイル シート テーマを使用して設定することはできません。詳細については、ThemeableAttribute、ASP.NET のテーマとスキンの概要 の各トピックを参照してください。

Checked プロパティを使用して、CheckBox コントロールの状態を確認する方法を次の例に示します。
![]() |
---|
次のコード サンプルはシングルファイル コード モデルを使用しており、分離コード ファイルに直接コピーされた場合は正常に動作しない可能性があります。このコード サンプルは、拡張子が .aspx の空のテキスト ファイルにコピーする必要があります。Web フォームのコード モデルの詳細については、「ASP.NET Web ページのコード モデル」を参照してください。 |
<%@ Page Language="VB" AutoEventWireup="True" %> <html> <head> <script runat="server"> Sub Check_Clicked(sender As Object, e As EventArgs) ' Calculate the subtotal and display the result in currency format. ' Include tax if the check box is selected. Message.Text = CalculateTotal(checkbox1.Checked).ToString("c") End Sub Sub Page_Load(sender As Object, e As EventArgs) ' Display the subtotal without tax when the page is first loaded. If Not IsPostBack Then ' Calculate the subtotal and display the result in currency format. Message.Text = CalculateTotal(false).ToString("c") End If End Sub Function CalculateTotal(Taxable As Boolean) As Double ' Calculate the subtotal for the example. Dim Result As Double = 1.99 + 2.99 + 3.99 ' Add tax, if applicable. If(Taxable) Result += Result * 0.086 End If Return Result End Function </script> </head> <body> <form runat="server"> <h3>CheckBox CheckedChanged Example</h3> Select whether to include tax in the subtotal. <br><br> <table border="1" cellpadding="5"> <tr> <th colspan="2"> Shopping cart </th> </tr> <tr> <td> Item 1 </td> <td> $1.99 </td> </tr> <tr> <td> Item 2 </td> <td> $2.99 </td> </tr> <tr> <td> Item 3 </td> <td> $3.99 </td> </tr> <tr> <td> <b>Subtotal</b> </td> <td> <asp:Label id="Message" runat="server"/> </td> </tr> <tr> <td colspan="2"> <asp:CheckBox id="checkbox1" runat="server" AutoPostBack="True" Text="Include 8.6% sales tax" TextAlign="Right" OnCheckedChanged="Check_Clicked"/> </td> </tr> </table> </form> </body> </html>
<%@ Page Language="C#" AutoEventWireup="True" %> <html> <head> <script runat="server"> void Check_Clicked(Object sender, EventArgs e) { // Calculate the subtotal and display the result in currency format. // Include tax if the check box is selected. Message.Text = CalculateTotal(checkbox1.Checked).ToString("c"); } void Page_Load(Object sender, EventArgs e) { // Display the subtotal without tax when the page is first loaded. if(!IsPostBack) { // Calculate the subtotal and display the result in currency format. Message.Text = CalculateTotal(false).ToString("c"); } } double CalculateTotal(bool Taxable) { // Calculate the subtotal for the example. double Result = 1.99 + 2.99 + 3.99; // Add tax, if applicable. if(Taxable) { Result += Result * 0.086; } return Result; } </script> </head> <body> <form runat="server"> <h3>CheckBox CheckedChanged Example</h3> Select whether to include tax in the subtotal. <br><br> <table border="1" cellpadding="5"> <tr> <th colspan="2"> Shopping cart </th> </tr> <tr> <td> Item 1 </td> <td> $1.99 </td> </tr> <tr> <td> Item 2 </td> <td> $2.99 </td> </tr> <tr> <td> Item 3 </td> <td> $3.99 </td> </tr> <tr> <td> <b>Subtotal</b> </td> <td> <asp:Label id="Message" runat="server"/> </td> </tr> <tr> <td colspan="2"> <asp:CheckBox id="checkbox1" runat="server" AutoPostBack="True" Text="Include 8.6% sales tax" TextAlign="Right" OnCheckedChanged="Check_Clicked"/> </td> </tr> </table> </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.Checked プロパティ
アセンブリ: System.Windows.Forms (system.windows.forms.dll 内)

/** @property */ public boolean get_Checked () /** @property */ public void set_Checked (boolean value)
CheckBox がチェックされた状態である場合は true。それ以外の場合は false。既定値は false です。
![]() |
---|
ThreeState プロパティが true に設定されている場合、Checked プロパティは、CheckState が Checked または Indeterminate である場合に true を返します。 |

値が true の場合は、コントロールの CheckBox 部分にチェック マークが表示されます。Appearance プロパティが Button に設定されていると、Checked が true のときにはコントロールがくぼんで表示され、false のときには標準のボタンのように浮き出て表示されます。

次のコード例では、ラベル内の 3 つのプロパティの値を示します。ThreeState プロパティは、コントロールをクリックするごとに、true と false の間で切り替わります。また CheckAlign の ContentAlignment 値は、MiddleRight と MiddleLeft の間で切り替わります。この例では、ThreeState プロパティが変更され、コントロールがオンになった場合に、プロパティ値がどのように変化するかを示します。このコードでは、CheckBox、Label、および Button がフォーム上ですべてインスタンス化されており、ラベルが 3 行のテキストを表示できる大きさであり、かつ System.Drawing 名前空間への参照が追加されている必要があります。このコードは、コントロールの Click イベント ハンドラで呼び出す必要があります。
Private Sub AdjustMyCheckBoxProperties() ' Concatenate the property values together on three lines. label1.Text = "ThreeState: " & checkBox1.ThreeState.ToString() & ControlChars.Cr & _ "Checked: " & checkBox1.Checked.ToString() & ControlChars.Cr & _ "CheckState: " & checkBox1.CheckState.ToString() ' Change the ThreeState and CheckAlign properties on every other click. If Not checkBox1.ThreeState Then checkBox1.ThreeState = True checkBox1.CheckAlign = ContentAlignment.MiddleRight Else checkBox1.ThreeState = False checkBox1.CheckAlign = ContentAlignment.MiddleLeft End If End Sub 'AdjustMyCheckBoxProperties
private void AdjustMyCheckBoxProperties() { // Concatenate the property values together on three lines. label1.Text = "ThreeState: " + checkBox1.ThreeState.ToString() + "\n" + "Checked: " + checkBox1.Checked.ToString() + "\n" + "CheckState: " + checkBox1.CheckState.ToString(); // Change the ThreeState and CheckAlign properties on every other click. if (!checkBox1.ThreeState) { checkBox1.ThreeState = true; checkBox1.CheckAlign = ContentAlignment.MiddleRight; } else { checkBox1.ThreeState = false; checkBox1.CheckAlign = ContentAlignment.MiddleLeft; } }
private: void AdjustMyCheckBoxProperties() { // Concatenate the property values together on three lines. label1->Text = String::Format( "ThreeState: {0}\nChecked: {1}\nCheckState: {2}", checkBox1->ThreeState, checkBox1->Checked, checkBox1->CheckState ); // Change the ThreeState and CheckAlign properties on every other click. if ( !checkBox1->ThreeState ) { checkBox1->ThreeState = true; checkBox1->CheckAlign = ContentAlignment::MiddleRight; } else { checkBox1->ThreeState = false; checkBox1->CheckAlign = ContentAlignment::MiddleLeft; } }
private void AdjustMyCheckBoxProperties() { // Concatenate the property values together on three lines. label1.set_Text("ThreeState: " + checkBox1.get_ThreeState() + "\n" + "Checked: " + checkBox1.get_Checked() + "\n" + "CheckState: " + checkBox1.get_CheckState()); //Change the ThreeState and CheckAlign properties on every other click. if (!(checkBox1.get_ThreeState())) { checkBox1.set_ThreeState(true); checkBox1.set_CheckAlign(ContentAlignment.MiddleRight); } else { checkBox1.set_ThreeState(false); checkBox1.set_CheckAlign(ContentAlignment.MiddleLeft); } } //AdjustMyCheckBoxProperties
private function AdjustMyCheckBoxProperties() { // Concatenate the property values together on three lines. label1.Text = "ThreeState: " + checkBox1.ThreeState.ToString() + "\n" + "Checked: " + checkBox1.Checked.ToString() + "\n" + "CheckState: " + checkBox1.CheckState.ToString(); // Change the ThreeState and CheckAlign properties on every other click. if (!checkBox1.ThreeState) { checkBox1.ThreeState = true; checkBox1.CheckAlign = ContentAlignment.MiddleRight; } else { checkBox1.ThreeState = false; checkBox1.CheckAlign = ContentAlignment.MiddleLeft; } }

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 によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


- CheckBox.Checkedのページへのリンク