DevExpress Winform:纯代码方式创建PopupMenu

2021-01-08 22:29

阅读:637

标签:orm   void   enc   ble   partial   bsp   事件   tco   work   

DevExpress版本:18.1

.NET Framework版本:4.0

VS版本:2017

C#语言版本:7.3

 1 public partial class YourClass : XtraForm
 2 {
 3     private readonly PopupMenu PopupMenu = new PopupMenu();
 4     private readonly BarManager BarManager = new BarManager();
 5 
 6     public YourClass()
 7     {
 8         // constructor
 9     }
10 
11     private void InitContextMenuGridControlDbTables()
12     {
13         this.PopupMenu.BeginInit();
14         this.BarManager.BeginInit();
15 
16         var menuRefresh = new BarButtonItem
17         {
18             Manager = this.BarManager,
19             Caption = "Refresh",
20             Name = "Refresh",
21             Id = 0
22         };
23         // menuRefresh.ItemClick += this.WhenClickRefresh;
24 
25         var menuSynchronize = new BarButtonItem
26         {
27             Manager = this.BarManager,
28             Caption = "Synchronize",
29             Name = "Synchronize",
30             Id = 1
31         };
32         // menuSynchronize.ItemClick += this.WhenClickSynchronize;
33 
34         var menuPurge = new BarButtonItem
35         {
36             Manager = this.BarManager,
37             Caption = "Purge",
38             Name = "Purge",
39             Id = 2
40         };
41         // menuPurge.ItemClick += this.WhenClickPurge;
42 
43         var menuRemove = new BarButtonItem
44         {
45             Manager = this.BarManager,
46             Caption = "Remove",
47             Name = "Remove",
48             Id = 3
49         };
50         // menuRemove.ItemClick += this.WhenClickRemove;
51 
52         this.PopupMenu.LinksPersistInfo.AddRange(new[]
53         {
54             new LinkPersistInfo(menuRefresh),
55             new LinkPersistInfo(menuSynchronize, true), // 第二个参数true,表示在Synchronize和Refresh菜单之间添加分割线
56             new LinkPersistInfo(menuPurge, true), // 第二个参数true,表示在Purge和Synchronize菜单之间添加分割线
57             new LinkPersistInfo(menuRemove)
58         });
59         this.PopupMenu.Manager = this.BarManager;
60 
61         this.BarManager.Form = this.gridControlDbTables; // BarManager.Form属性表示菜单所属的控件
62         this.BarManager.Items.AddRange(new BarItem[]
63         {
64             menuRefresh,
65             menuSynchronize,
66             menuPurge,
67             menuRemove
68         });
69 
70         this.PopupMenu.EndInit();
71         this.BarManager.EndInit();
72 
73         // 绑定BarManager.Form控件的MouseUp事件以显示菜单
74         this.gridControlDbTables.MouseUp += (sender, e) =>
75         {
76             if (MouseButtons.Right == e.Button)
77                 this.PopupMenu.ShowPopup(Control.MousePosition);
78         };
79     }
80 }

 

DevExpress Winform:纯代码方式创建PopupMenu

标签:orm   void   enc   ble   partial   bsp   事件   tco   work   

原文地址:https://www.cnblogs.com/yitouniu/p/13123857.html


评论


亲,登录后才可以留言!