`
touchinsert
  • 浏览: 1289862 次
  • 性别: Icon_minigender_1
  • 来自: 北京
文章分类
社区版块
存档分类
最新评论

DevExpress 给TreeList添加右键菜单

 
阅读更多

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

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. privatevoidtreeList1_MouseUp(objectsender,MouseEventArgse)
  2. {
  3. TreeListtree=senderasTreeList;
  4. if(e.Button==MouseButtons.Right
  5. &&ModifierKeys==Keys.None
  6. &&treeList1.State==TreeListState.Regular)
  7. {
  8. Pointp=newPoint(Cursor.Position.X,Cursor.Position.Y);
  9. TreeListHitInfohitInfo=tree.CalcHitInfo(e.Location);
  10. if(hitInfo.HitInfoType==HitInfoType.Cell)
  11. {
  12. tree.SetFocusedNode(hitInfo.Node);
  13. }
  14. if(tree.FocusedNode!=null)
  15. {
  16. popupMenu1.ShowPopup(p);
  17. }
  18. }
  19. }
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics