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