MenuItem.RadioCheck 属性
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
获取或设置一个值,通过该值指示 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
。 事件处理程序确定单击了哪个菜单项,在所选菜单项上放置复选标记,并更改名为 的窗体控件TextBoxtextBox1
的文本颜色。 该示例还使用 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
注解
复选标记不一定意味着一组菜单项的互斥状态。 可以使用此属性向用户指示菜单项的检查标记是互斥的。