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 grid;
10 
11 import std..string;
12 import dgui.all;
13 import dgui.layout.gridpanel;
14 
15 class MainForm: Form
16 {
17 	private GridPanel _gridPanel;
18 	private Collection!(Label) _labels;
19 	private Collection!(TextBox) _textboxes;
20 	private Collection!(Button) _buttons;
21 
22 	public this()
23 	{
24 		this.text = "DGui SplitPanel Example";
25 		this.size = Size(400, 400);
26 		this.maximizeBox = false;
27 		this.minimizeBox = false;
28 		this.startPosition = FormStartPosition.centerScreen;
29 		this.formBorderStyle = FormBorderStyle.fixedDialog;
30 
31 		this._gridPanel = new GridPanel();
32 		this._gridPanel.dock = DockStyle.fill;
33 		this._gridPanel.parent = this;
34 
35 		this._labels = new Collection!(Label);
36 		this._textboxes = new Collection!(TextBox);
37 		this._buttons = new Collection!(Button);
38 
39 		// Add 10 rows
40 		for(int i = 0; i < 10; i++)
41 		{
42 			RowPart row = this._gridPanel.addRow();
43 			row.marginTop = 4; // Set 4 pixel of empty space (top part) for this row
44 			row.height = 23; //If you don't set the row's height, it will be used the component's height (if set)
45 
46 			string s = format("Row No. %d", i);
47 
48 			/* COLUMN 1 */
49 			Label lbl = new Label();
50 			lbl.text = s;
51 			lbl.alignment = TextAlignment.middle | TextAlignment.left;
52 
53 			ColumnPart col1 = row.addColumn(lbl); //Add the component in the column 1, this parameter can be 'null' if you want to add an empty space
54 			col1.width = 60; //If you don't set the column's width, it will be used the component's width (if set)
55 			col1.marginLeft = 4; // Set 4 pixel of empty space (left part) for column 1
56 
57 			/* COLUMN 2 */
58 			TextBox tbx = new TextBox();
59 			tbx.text = s;
60 
61 			ColumnPart col2 = row.addColumn(tbx); //Add the component in the column 2, this parameter can be 'null' if you want to add an empty space
62 			col2.width = 80; //If you don't set the column's width, it will be used the component's width (if set)
63 			col2.marginRight = 4; // Set 4 pixel of empty space (right part) for column 2
64 
65 			/* COLUMN 3 */
66 			Button btn = new Button();
67 			btn.text = "Click Me!";
68 			btn.tag = tbx; // Save the TextBox (just for this sample, is not needed for GridPanel)
69 			btn.click.attach(&this.onBtnClick);
70 
71 			ColumnPart col3 = row.addColumn(btn); //Add the component in the column 2, this parameter can be 'null' if you want to add an empty space
72 			col3.width = 60; //If you don't set the column's width, it will be used the component's width (if set)
73 
74 			this._labels.add(lbl);
75 			this._textboxes.add(tbx);
76 			this._buttons.add(btn);
77 		}
78 	}
79 
80 	private void onBtnClick(Control sender, EventArgs e)
81 	{
82 		TextBox tbx = sender.tag!(TextBox);
83 		MsgBox.show("Click Event", tbx.text);
84 	}
85 }
86 
87 int main(string[] args)
88 {
89 	return Application.run(new MainForm());
90 }