首页 > 其他分享 >DevExpress 给TreeList添加右键菜单

DevExpress 给TreeList添加右键菜单

时间:2022-12-05 12:35:37浏览次数:66  
标签:node treeList1 DevExpress tree popupMenu 添加 右键 TreeList null


只有在右击节点时才会触发

private void treeList1_MouseDown(object sender, MouseEventArgs e)
{ if (e.Button == MouseButtons.Right)
{
treeList1.ContextMenuStrip = null; TreeListHitInfo hInfo = treeList1.CalcHitInfo(new Point(e.X, e.Y));
TreeListNode node = hInfo.Node;
treeList1.FocusedNode = node;
if (node!=null)
{
treeList1.ContextMenuStrip = contextMenuStrip1;
}
} }

 添加BarManager和popupMenu组建:


 

 

设置popupMenu组件的Manager属性:

 

 

右键点击popupMenu主键,点击Customize选项添加菜单:

 


 然后便可添加到鼠标事件中,此处以TreeList为例:

 


C#代码 ​​ ​

     
1. private void treeList1_MouseUp(object
2. {
3. as
4. if
5. && ModifierKeys == Keys.None
6. && treeList1.State == TreeListState.Regular)
7. {
8. new
9. TreeListHitInfo hitInfo = tree.CalcHitInfo(e.Location);
10. if
11. {
12. tree.SetFocusedNode(hitInfo.Node);
13. }
14.
15. if (tree.FocusedNode != null)
16. {
17. popupMenu1.ShowPopup(p);
18. }
19. }
20. }

标签:node,treeList1,DevExpress,tree,popupMenu,添加,右键,TreeList,null
From: https://blog.51cto.com/u_11295556/5911884

相关文章