MenuItem.Checked プロパティ

定義

メニュー項目のテキストの横にチェック マークを表示するかどうかを示す値を取得または設定します。

public:
 property bool Checked { bool get(); void set(bool value); };
public bool Checked { get; set; }
member this.Checked : bool with get, set
Public Property Checked As Boolean

プロパティ値

メニュー項目の隣にチェック マークがある場合は true。それ以外の場合は false。 既定値は、false です。

例外

MenuItem はトップレベル メニューであるか、子があります。

次のコード例では、 プロパティを Checked 使用して、アプリケーションの状態を指定します。 この例では、メニュー項目のグループを使用して、コントロール内のテキストの色を TextBox 指定します。 提供されるイベント ハンドラーは、3 つのメニュー項目のイベントによって Click 使用されます。 各メニュー項目は、テキストの色、(赤)、(緑) menuItemGreenmenuItemRed または menuItemBlue (青) を指定します。 イベント ハンドラーは、クリックされたメニュー項目を決定し、選択したメニュー項目にチェックマークを付け、フォームの TextBox コントロールのテキストの色を変更します。 この例では、このコードが System.Drawing 配置されているフォームに名前空間が追加されている必要があります。 この例では、 という TextBox 名前 textBox1の コード例が配置されているフォームに が追加されている必要もあります。

private:
   // The following event handler would be connected to three menu items.
   void MyMenuClick( Object^ sender, EventArgs^ e )
   {
      // Determine if clicked menu item is the Blue menu item.
      if ( sender == menuItemBlue )
      {
         // Set the checkmark for the menuItemBlue menu item.
         menuItemBlue->Checked = true;
         // Uncheck the menuItemRed and menuItemGreen menu items.
         menuItemRed->Checked = false;
         menuItemGreen->Checked = false;
         // Set the color of the text in the TextBox control to Blue.
         textBox1->ForeColor = Color::Blue;
      }
      else if ( sender == menuItemRed )
      {
         
         // Set the checkmark for the menuItemRed menu item.
         menuItemRed->Checked = true;
         // Uncheck the menuItemBlue and menuItemGreen menu items.
         menuItemBlue->Checked = false;
         menuItemGreen->Checked = false;
         // Set the color of the text in the TextBox control to Red.
         textBox1->ForeColor = Color::Red;
      }
      else
      {
         // Set the checkmark for the menuItemGreen.
         menuItemGreen->Checked = true;
         // Uncheck the menuItemRed and menuItemBlue menu items.
         menuItemBlue->Checked = false;
         menuItemRed->Checked = false;
         // Set the color of the text in the TextBox control to Blue.
         textBox1->ForeColor = Color::Green;
      }
   }
// The following event handler would be connected to three menu items.
 private void MyMenuClick(Object sender, EventArgs e)
 {
    // Determine if clicked menu item is the Blue menu item.
    if(sender == menuItemBlue)
    {
       // Set the checkmark for the menuItemBlue menu item.
       menuItemBlue.Checked = true;
       // Uncheck the menuItemRed and menuItemGreen menu items.
       menuItemRed.Checked = false;
       menuItemGreen.Checked = false;
       // Set the color of the text in the TextBox control to Blue.
       textBox1.ForeColor = Color.Blue;
    }
    else if(sender == menuItemRed)
    {
       // Set the checkmark for the menuItemRed menu item.
       menuItemRed.Checked = true;
       // Uncheck the menuItemBlue and menuItemGreen menu items.
       menuItemBlue.Checked = false;
       menuItemGreen.Checked = false;
       // Set the color of the text in the TextBox control to Red.
       textBox1.ForeColor = Color.Red;
    }
    else
    {
       // Set the checkmark for the menuItemGreen.
       menuItemGreen.Checked = true;
       // Uncheck the menuItemRed and menuItemBlue menu items.
       menuItemBlue.Checked = false;
       menuItemRed.Checked = false;
       // Set the color of the text in the TextBox control to Blue.
       textBox1.ForeColor = Color.Green;
    }
 }
' The following event handler would be connected to three menu items.
Private Sub MyMenuClick(sender As Object, e As EventArgs)
    ' Determine if clicked menu item is the Blue menu item.
    If sender Is menuItemBlue Then
        ' Set the checkmark for the menuItemBlue menu item.
        menuItemBlue.Checked = True
        ' Uncheck the menuItemRed and menuItemGreen menu items.
        menuItemRed.Checked = False
        menuItemGreen.Checked = False
        ' Set the color of the text in the TextBox control to Blue.
        textBox1.ForeColor = Color.Blue
    Else
        If sender Is menuItemRed Then
            ' Set the checkmark for the menuItemRed menu item.
            menuItemRed.Checked = True
            ' Uncheck the menuItemBlue and menuItemGreen menu items.
            menuItemBlue.Checked = False
            menuItemGreen.Checked = False
            ' Set the color of the text in the TextBox control to Red.
            textBox1.ForeColor = Color.Red
        Else
            ' Set the checkmark for the menuItemGreen.
            menuItemGreen.Checked = True
            ' Uncheck the menuItemRed and menuItemBlue menu items.
            menuItemBlue.Checked = False
            menuItemRed.Checked = False
            ' Set the color of the text in the TextBox control to Blue.
            textBox1.ForeColor = Color.Green
        End If
    End If
End Sub

注釈

プロパティをメニュー内の Checked 他のメニュー項目と組み合わせて使用すると、アプリケーションの状態を指定できます。 たとえば、項目のグループ内のメニュー項目にチェックマークを配置して、アプリケーション内のテキストに表示するフォントのサイズを識別できます。 また、 プロパティを Checked 使用して、相互に排他的なメニュー項目のグループ内で選択したメニュー項目を識別することもできます。

注意

このプロパティは、最上位のメニュー項目には に true 設定できません。

適用対象