MenuItem.RadioCheck プロパティ

定義

MenuItem がチェックされている場合、チェック マークの代わりにオプション ボタンを表示するかどうかを示す値を取得または設定します。

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

プロパティ値

メニュー項目がチェックされた場合に、チェック マークの代わりにオプション ボタンが使用される場合は true。標準のチェック マークが表示される場合は false。 既定値は、false です。

次のコード例では、 プロパティを Checked 使用してアプリケーションの状態を変更します。 この例では、コントロール内のテキストの色を指定するために使用されるメニュー項目のグループが TextBox 用意されています。 この例では、指定されたイベント ハンドラーが、3 つのメニュー項目のイベントによって Click 使用されます。 各メニュー項目は、色、menuItemRedmenuItemGreenまたは menuItemBlueを指定します。 イベント ハンドラーは、クリックされたメニュー項目を決定し、選択したメニュー項目にチェックマークを付け、 という名前textBox1のフォームのコントロールのTextBoxテキストの色を変更します。 また、この例では、 プロパティをRadioCheck使用して、相互に排他的なメニュー項目を表示するためにラジオ ボタン チェックを使用する方法を示します。 この例では、このコードを System.Drawing 含むフォームに名前空間が追加されている必要があります。

public:
   // This method is called from the constructor of the form to set up the menu items.
   void ConfigureMyMenus()
   {
      /* Set all of these menu items to Radio-Button check marks so the user can see 
         that only one color can be selected at a time. */
      menuItemRed->RadioCheck = true;
      menuItemBlue->RadioCheck = true;
      menuItemGreen->RadioCheck = true;
   }

private:
   // The following event handler would be connected to three menu items.
   void MyMenuClick( Object^ sender, EventArgs^ e )
   {
      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 menu item.
         menuItemGreen->Checked = true;
         // Uncheck the menuItemRed and menuItemGreen menu items.
         menuItemBlue->Checked = false;
         menuItemRed->Checked = false;
         // Set the color of the text in the TextBox control to Blue.
         textBox1->ForeColor = Color::Green;
      }
   }
// This method is called from the constructor of the form to set up the menu items.
public void ConfigureMyMenus()
{
   /* Set all of these menu items to Radio-Button check marks so the user can see 
      that only one color can be selected at a time. */
   menuItemRed.RadioCheck = true;
   menuItemBlue.RadioCheck = true;
   menuItemGreen.RadioCheck = true;
}

// The following event handler would be connected to three menu items.
private void MyMenuClick(Object sender, EventArgs e)
{
   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 menu item.
      menuItemGreen.Checked = true;
      // Uncheck the menuItemRed and menuItemGreen menu items.
      menuItemBlue.Checked = false;
      menuItemRed.Checked = false;
      // Set the color of the text in the TextBox control to Blue.
      textBox1.ForeColor = Color.Green;
   }
}
' This method is called from the constructor of the form to set up the menu
' items.
Public Sub ConfigureMyMenus()
    ' Set all of these menu items to Radio-Button check marks so the user
    ' can see that only one color can be selected at a time. 
    menuItemRed.RadioCheck = True
    menuItemBlue.RadioCheck = True
    menuItemGreen.RadioCheck = True
End Sub    

' The following event handler would be connected to three menu items.
Private Sub MyMenuClick(sender As Object, e As EventArgs)
    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 menu item.
            menuItemGreen.Checked = True
            ' Uncheck the menuItemRed and menuItemGreen 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

注釈

チェック マークは、メニュー項目のグループに対して相互に排他的な状態であるとは限りません。 このプロパティを使用すると、メニュー項目のチェックマークが相互に排他的であることをユーザーに示すことができます。

適用対象

こちらもご覧ください