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 управления . В этом примере предоставленный обработчик событий используется событием Click трех пунктов меню. Каждый пункт меню задает цвет, menuItemRed, menuItemGreenили menuItemBlue. Обработчик событий определяет, какой пункт меню был выбран, устанавливает флажок к выбранному элементу меню и изменяет цвет текста элемента управления формы TextBox с именем textBox1. В примере также используется 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

Комментарии

Флажки не обязательно подразумевают взаимоисключающее состояние для группы пунктов меню. Это свойство можно использовать, чтобы указать пользователю, что проверка знак пункта меню является взаимоисключающим.

Применяется к

См. также раздел