1 module menu;
2 
3 import dguihub;
4 
5 class MainForm : Form {
6    private MenuBar _mainMenu;
7 
8    public this() {
9       this.text = "DGui Menu Test";
10       this.size = Size(500, 400);
11       this.startPosition = FormStartPosition.centerScreen; // Set Form Position
12 
13       this._mainMenu = new MenuBar();
14       MenuItem m1 = this._mainMenu.addItem("Menu 1"); //Menu 1
15       MenuItem m2 = this._mainMenu.addItem("Menu 2"); //Menu 2
16       MenuItem m3 = this._mainMenu.addItem("Menu 3"); //Menu 3
17 
18       MenuItem m1_1 = m1.addItem("Menu 1.1"); //Add new menu item in Menu 1
19       MenuItem m1_2 = m1.addItem("Menu 1.2"); //Add new menu item in Menu 1
20       MenuItem m1_3 = m1.addItem("Menu 1.3"); //Add new menu item in Menu 1
21 
22       /* Menu 2 Creation */
23       m2.addItem("Menu 2.1");
24       m2.addItem("Menu 2.2", false); // Disable this menu item
25       m2.addSeparator(); //Add a separator
26       m2.addItem("Menu 2.3");
27 
28       /* Creazione Menu 3 */
29       m3.addItem("Menu 3.1");
30       m3.addItem("Menu 3.2");
31       m3.addSeparator(); //Add a separator
32       m3.addItem("Menu 3.3", false); // Disable this menu item
33 
34       m1_1.click.attach(&this.onMenu1_1Click); // Link the click event
35       m1_2.click.attach(&this.onMenu1_2Click); // Link the click event
36       m1_3.click.attach(&this.onMenu1_3Click); // Link the click event
37 
38       this.menu = this._mainMenu; // Associate the menu previously created with the form
39    }
40 
41    private void onMenu1_1Click(MenuItem sender, EventArgs e) {
42       MsgBox.show("Menu 1 -> 1.1 Click", "Menu 1 -> 1");
43    }
44 
45    private void onMenu1_2Click(MenuItem sender, EventArgs e) {
46       MsgBox.show("Menu 1 -> 1.2 Click", "Menu 1 -> 1");
47    }
48 
49    private void onMenu1_3Click(MenuItem sender, EventArgs e) {
50       MsgBox.show("Menu 1 -> 1.3 Click", "Menu 1 -> 1");
51    }
52 }
53 
54 int main(string[] args) {
55    return Application.run(new MainForm()); // Start the application
56 }