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