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

查看:142
本文介绍了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 ,并设置链接到复选框,如果你使用的可能性 CheckOnClick 属性真正你可帮了的CheckedChanged 事件为应挂钩,而该事件处理程序内使 ToolStripMenuItem 复选框控制相同的事件处理程序确保控件的经过属性同步并执行任何其他必要的行动。

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天全站免登陆