C#添加复选框到WinForms上下文菜单 [英] C# Add Checkbox To WinForms Context Menu

查看:140
本文介绍了C#添加复选框到WinForms上下文菜单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在表单上有一系列复选框。
我想能够从上下文菜单中选择这些以及窗体本身。上下文菜单链接到应用程序的系统托盘图标。

I have a series of checkboxes on a form. I want to be able to select these from a context menu as well as the form itself. The context menu is linked to the system tray icon of the application.

我的问题是,是否可以链接上下文菜单到这些复选框?
或者甚至可以添加复选框到上下文菜单?
甚至一个组合?

My question is, is it possible to link the context menu to these checkboxes? Or even possible to add checkboxes to the context menu? Or even a combination?!

推荐答案

菜单项有检查属性( MenuItem.Checked ToolStripMenuItem.Checked ),您可以用于此目的。

The menu items have a Checked property (MenuItem.Checked, ToolStripMenuItem.Checked) that you can use for this purpose.

关于将上下文菜单项链接到复选框的可能性,如果使用 ContextMenuStrip code> 属性为 true ,可以连接 CheckedChanged 事件到相同的事件处理程序为 ToolStripMenuItem CheckBox 控件应该是链接确保同步控件的检查属性,并执行任何其他所需的操作。

Regarding the possibility to link the context menu items to the check boxes, if you use a ContextMenuStrip and set CheckOnClick property to true, you can hook up the CheckedChanged events to the same event handler for the ToolStripMenuItem and CheckBox controls that should be "linked", and inside that event handler make sure to synchronize the Checked property of the controls and perform any other needed actions.

这篇关于C#添加复选框到WinForms上下文菜单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆