CheckBox クラスとは? わかりやすく解説

CheckBox クラス

チェック ボックス表示されtrue または false条件選択できます

名前空間: System.Web.UI.WebControls
アセンブリ: System.Web (system.web.dll 内)
構文構文

<ControlValuePropertyAttribute("Checked")> _
Public Class CheckBox
    Inherits WebControl
    Implements IPostBackDataHandler, ICheckBoxControl
[ControlValuePropertyAttribute("Checked")] 
public class CheckBox : WebControl, IPostBackDataHandler,
 ICheckBoxControl
[ControlValuePropertyAttribute(L"Checked")] 
public ref class CheckBox : public
 WebControl, IPostBackDataHandler, ICheckBoxControl
/** @attribute ControlValuePropertyAttribute("Checked") */ 
public class CheckBox extends WebControl implements
 IPostBackDataHandler, ICheckBoxControl
ControlValuePropertyAttribute("Checked") 
public class CheckBox extends
 WebControl implements IPostBackDataHandler, ICheckBoxControl
解説解説

CheckBox使用すると、true または false の状態を選択できます

複数CheckBox コントロール使用する場合は、CheckBoxList コントロール代替コントロールとして使用できます。このコントロールでは、便利なデータ連結機能提供しますそれぞれの CheckBox コントロールには強力なレイアウト制御機能用意されています。

注意に関するメモ注意

このコントロールは、ユーザー入力表示するために使用できますユーザー入力には悪意のあるクライアント スクリプト含まれている可能性ありますアプリケーション表示する前にクライアントから送信され実行スクリプトSQL ステートメントなどのコード情報はすべて検証してください入力テキストコントロール表示する前に検証コントロール使用してユーザー入力検証できますASP.NET には入力要求検証機能があり、ユーザー入力の中のスクリプトおよび HTMLブロックできます詳細については、「標準コントロールセキュリティ保護」、「方法 : HTML エンコーディング文字列適用して Web アプリケーションスクリプトによる攻略から保護する」、および「ASP.NET Web ページにおけるユーザー入力検証」を参照してください

ユーザー補助

使用例使用例

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>

.NET Framework のセキュリティ.NET Frameworkセキュリティ
継承階層継承階層
System.Object
   System.Web.UI.Control
     System.Web.UI.WebControls.WebControl
      System.Web.UI.WebControls.CheckBox
         System.Web.UI.WebControls.RadioButton
スレッド セーフスレッド セーフ
この型の public static (Visual Basic では Shared) メンバはすべて、スレッド セーフです。インスタンス メンバ場合は、スレッド セーフであるとは限りません。
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

CheckBox クラス

Windows CheckBox表します

名前空間: System.Windows.Forms
アセンブリ: System.Windows.Forms (system.windows.forms.dll 内)
構文構文

<ComVisibleAttribute(True)> _
<ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch)> _
Public Class CheckBox
    Inherits ButtonBase
[ComVisibleAttribute(true)] 
[ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch)] 
public class CheckBox : ButtonBase
[ComVisibleAttribute(true)] 
[ClassInterfaceAttribute(ClassInterfaceType::AutoDispatch)] 
public ref class CheckBox : public
 ButtonBase
/** @attribute ComVisibleAttribute(true) */ 
/** @attribute ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch) */ 
public class CheckBox extends ButtonBase
ComVisibleAttribute(true) 
ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch) 
public class CheckBox extends
 ButtonBase
解説解説

CheckBox使用すると、ユーザーに true/false、yes/no などのオプション提示できますCheckBox コントロールは、イメージテキスト、またはその両方表示できます

CheckBox コントロールRadioButton コントロールには似た機能があり、ユーザーオプションリストから選択できるようにします。CheckBox コントロールは、複数オプション組み合わせて選択できるようにします。これに対して RadioButton コントロールは、複数オプションから 1 つだけ選択できるようにします。

Appearance プロパティは、CheckBox通常のCheckBox表示するのか、またはボタン表示するのかを決定します

ThreeState プロパティは、コントロールで 2 ステートと 3 ステートのどちらをサポートするのかを決定しますChecked プロパティは、2 ステートCheckBox コントロールの値を取得または設定するために使用し、CheckState プロパティは、3 ステートCheckBox コントロールの値を取得または設定するために使用します

メモメモ

ThreeState プロパティtrue設定されている場合Checked プロパティは、チェックされた状態と中間状態のどちらであるかを示す true返します

FlatStyle プロパティは、コントロールスタイル外観決定しますFlatStyle プロパティが FlatStyle.System に設定されている場合は、ユーザー使用しているオペレーティング システムによってコントロール外観決定されます。

メモメモ

FlatStyle プロパティFlatStyle.System設定されていると、CheckAlign プロパティの値は無視されコントロールは ContentAlignment.MiddleLeft 値または ContentAlignment.MiddleRight 値を使用して整列および表示されます。CheckAlign プロパティの値が右揃え1 つ設定されている場合コントロールContentAlignment.MiddleRight 値を使用して整列および表示されます。それ以外場合は、ContentAlignment.MiddleLeft 値が使用されます。

中間態とは、次のような状態です。RichTextBox で選択したテキスト太字にするかどうか決定する CheckBox があるとしますテキスト選択して CheckBoxクリックすると、選択したテキスト太字なります同様にテキスト選択すると、選択したテキスト太字かどうかCheckBox表示されます。選択したテキスト太字標準両方テキストがある場合CheckBox中間態となります

使用例使用例

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);
 }
 
継承階層継承階層
System.Object
   System.MarshalByRefObject
     System.ComponentModel.Component
       System.Windows.Forms.Control
         System.Windows.Forms.ButtonBase
          System.Windows.Forms.CheckBox
スレッド セーフスレッド セーフ
この型の public static (Visual Basic では Shared) メンバはすべて、スレッド セーフです。インスタンス メンバ場合は、スレッド セーフであるとは限りません。
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照



英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

「CheckBox クラス」の関連用語

CheckBox クラスのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



CheckBox クラスのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2024 Microsoft.All rights reserved.

©2024 GRAS Group, Inc.RSS