当用户控件处于活动状态时如何使上下文菜单不可选择 [英] How to make context menu as non selectable when the usercontrol is active

查看:109
本文介绍了当用户控件处于活动状态时如何使上下文菜单不可选择的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我右键单击树视图的节点时,我正在显示一个上下文菜单.假设我的树视图如下

根|-> some.txt |->子级(For some.txt)|-> Child1(Child for Child)

如果我在Child1上单击鼠标右键,则可以选择AddNew.如果用户选择,我将为面板中显示的用户显示用户控制表单.

我需要的是,如果用户选择该选项作为Child1,并且用户控件处于活动状态,并且当用户再次右键单击

I am having a context menu displayed when i right click on a node of a treeview. Suppose my treeview is as follows

Root |->some.txt |-> Child(For some.txt) |-> Child1(child for Child)

If i right click on Child1 i will have an option as AddNew. If the user selects i will show a user control form for the user displayed in a panel.

What i need is if the user selects the option as Child1 and if the user control is active and when the user again right clicks

推荐答案

似乎需要几个不同的上下文时,菜单,其中根据上下文菜单启动时鼠标下方的树节点显示不同的菜单.

使用MouseDown事件更改上下文菜单的可见项.该事件获取一个包含X和Y坐标的MouseEventArgs参数.

您可以使用Treeview.HitTest(Point)方法在鼠标的当前位置获取节点.

如果在显示上下文菜单之前未引发该事件,则可以尝试热跟踪",即使用MouseMove事件而不是MouseDown.它不会很有效,因为它会经常执行,但是会起作用.
seems like you need several different context menu''s where a different menu is displayed depending on which tree node was under the mouse at the time the context menu was initiated.

Use the MouseDown event to alter the context menu''s visible items. The event gets a MouseEventArgs parameter that contains X and Y coordinates.

You can use the Treeview.HitTest( Point ) method to get the node at the mouse''s current location.

If that event isn''t raised before the context menu is shown you could try "hot tracking" i.e. using the MouseMove event instead of MouseDown. It won''t be very efficient because it will execute very often, but it will work.


如果我的问题正确的话……如果您正在寻找一种控制方法,为不同节点显示的上下文菜单,您只需在节点上分配正确的上下文菜单

当您填充树视图控件时

If I got your questions right ... if you are looking for a way to control the context menu displayed for different nodes you can just assign the right context menu on the node

when you are populating the treeview control

TreeNode nd= TreeView1.Nodes.AddNode("Sometext.txt");
nd.ContextMenu=ContextMenu1;



除此之外...您正在寻找的是可能有些混乱的澄清信息,我们可以为您提供更多帮助.:confused :: confused :: confused :: confused :: confused :: confused:



other than that ... what you are looking for is a bit confusing may be with clarifications we can help you more.:confused::confused::confused::confused::confused::confused:


这篇关于当用户控件处于活动状态时如何使上下文菜单不可选择的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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