DevExpress Winform:纯代码方式创建PopupMenu
Posted yitouniu
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了DevExpress Winform:纯代码方式创建PopupMenu相关的知识,希望对你有一定的参考价值。
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的主要内容,如果未能解决你的问题,请参考以下文章
Winform使用DevExpress的WaitDialogForm画面
在DevExpress程序中使用Winform分页控件直接录入数据并保存