取消选择 ContextMenuStrip 上的 ToolStripItem [英] Deselect ToolStripItem on ContextMenuStrip

查看:31
本文介绍了取消选择 ContextMenuStrip 上的 ToolStripItem的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

简单的问题:

我可以.Select一个ToolStripItem(比如,如果我在打开上下文菜单条时想要一个预选的选项)但我似乎找不到设置.Selected 为 false 或以某种方式取消选择它!

I can .Select a ToolStripItem (like, if i want a preselected option when opening a context menu strip) but i cannot seem to find a way to set .Selected to false or somehow deselect it!

有可能吗?

推荐答案

ToolStrip 类中有一个私有方法 ClearAllSelections,用于从项目中删除选择.您可以通过反射调用它:

There is private method ClearAllSelections in ToolStrip class, which removes selections from items. You can invoke it via reflection:

MethodInfo method = typeof(ToolStrip).GetMethod("ClearAllSelections", BindingFlags.NonPublic | BindingFlags.Instance);
method.Invoke(yourContextMenuStrip, null);

所有选择都将被删除.

这篇关于取消选择 ContextMenuStrip 上的 ToolStripItem的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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