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

旧街凉风 提交于 2019-12-01 13:49:09

If you navigate to

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

you will see how it's done ;)!

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!