MenuItem.RadioCheck 属性

定义

获取或设置一个值,通过该值指示 MenuItem(如果已选中)是否显示单选按钮而不是选中标记。Gets or sets a value indicating whether the MenuItem, if checked, displays a radio-button instead of a check mark.

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;如果菜单项选中时要显示的是标准选中标记,则为 falsetrue if a radio-button is to be used instead of a check mark; false if the standard check mark is to be displayed when the menu item is checked. 默认值为 falseThe default is false.

示例

下面的代码示例使用 Checked 属性更改应用程序的状态。The following code example uses the Checked property to change the state of an application. 在此示例中,提供了一组菜单项,这些菜单项用于指定 TextBox 控件中的文本的颜色。In the example, a group of menu items are provided that are used to specify the color for the text in an TextBox control. 在此示例中,提供的事件处理程序由三个菜单项的 Click 事件使用。In the example, the event handler provided is used by the Click event of the three menu items. 每个菜单项指定颜色、menuItemRedmenuItemGreenmenuItemBlueEach menu item specifies a color, menuItemRed, menuItemGreen, or menuItemBlue. 事件处理程序确定单击的菜单项,将复选标记置于所选菜单项,并更改窗体的 TextBox 控件的文本颜色,名为 textBox1The event handler determines which menu item was clicked, places a checkmark to the selected menu item, and changes the text color of the form's TextBox control, named textBox1. 该示例还使用 "RadioCheck" 属性来演示如何使用单选按钮来显示互斥的菜单项。The example also uses the RadioCheck property to demonstrate how a radio-button check is used to show menu items that are mutually exclusive. 此示例要求将 System.Drawing 命名空间添加到包含此代码的窗体中。This example requires that the System.Drawing namespace has been added to the form that contains this code.

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

注解

对于一组菜单项,复选标记不一定表示一组互斥状态。Check marks do not necessarily imply a mutually exclusive state for a group of menu items. 您可以使用此属性向用户指示菜单项的选中标记是互斥的。You can use this property to indicate to the user that the check mark of a menu item is mutually exclusive.

适用于

另请参阅