C# 帮助为 MenuStrip 添加单选按钮/选项按钮

发布于 2024-09-04 20:58:51 字数 207 浏览 1 评论 0原文

我是 C# 语言的初学者,所以我需要天才们对这个方案的一些帮助:我需要为菜单条添加一个单选按钮。我已将 CheckOnClick 属性更改为 true,但我需要一个用于单选按钮选择的选项。您可以从 Windows 计算器菜单栏查看它(单击“查看”)。 如何通过 MenuStrip 属性访问它?

I'm a beginner in C# language, so I need some help from the geniuses with this scheme: I need to add a radio 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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

〆一缕阳光ご 2024-09-11 20:58:51

我知道这是一篇近乎古老的帖子,但我认为值得一提的是,尽管没有对 RadioButton MenueItem 的本机支持,但很容易哄骗他们的复选框以这种方式表现。首先将每个 MenueItem 的 CheckOnClick 属性设置为 FALSE。然后将相同的 MouseDown 事件处理程序应用于每个项目:

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

您可以使用 Click 事件代替,但我更喜欢 MouseDown 因为它提供了一些可视化用户所检查的项目已更改,同时保持 Click 事件打开,以便在需要时对各个项目进行编码。

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.

清欢 2024-09-11 20:58:51

如果导航到

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

你会看到它是如何完成的;)!

If you navigate to

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

you will see how it's done ;)!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文