开发者

C# Help For Adding Radio Button / Options Button For MenuStrip

开发者 https://www.devze.com 2023-01-02 10:54 出处:网络
I\'m a beginner in C# language, so I need some help from the geniuses with this scheme: I need to add a r开发者_开发知识库adio button for a menu strip. I\'ve already changed the, CheckOnClick property

I'm a beginner in C# language, so I need some help from the geniuses with this scheme: I need to add a r开发者_开发知识库adio button for a menu strip. I've already changed the, CheckOnClick property to true, but I need an option for radio button selection. You can see it from the Windows calculator menu bar (click View). How can I get to it via the MenuStrip property?


I know this is a near-ancient post, but I thought it worth mentioning that although there's no native support for a RadioButton MenueItem, it's easy enough to coax their checkboxes into behaving that way. Start by setting the CheckOnClick property of each MenueItem to FALSE. Then apply the same MouseDown event handler to each item:

private void ToolStripMenueItem_MouseDown(object sender, MouseEventArgs e)
{
    var thisTsmi = (ToolStripMenuItem)sender;
    foreach (ToolStripMenuItem tsmi in thisTsmi.GetCurrentParent().Items)
    {
        tsmi.Checked = thisTsmi == tsmi;
    }
}

You could use the Click event instead, but I prefer MouseDown because it provides some visualization to the user that the checked item has changed while leaving the Click event open for coding the individual items if needed.


If you navigate to

msdn.microsoft.com/en-us/library/ms404318.aspx

you will see how it's done ;)!

0

精彩评论

暂无评论...
验证码 换一张
取 消