![]() If Assigned(aControl) AND (aControl IS TButton) then To get the control placed in a specified row / column you can use:ĪControl := //3rd row, 4th column Nice!Īnd two extras: Get Control at Row/Column As you resize the form, buttons grow or shrink but are still evenly distributed in 3×4 grid. So, on the form I have a GridPanel1 and the CreateButtonGrid(3,5) procedure will place 12 buttons in a 3 rows x 4 columns grid, each cell of the same size, buttons filling the cell with a pinch of margin. Value := 100 / colCount //have cells evenly distributedįor i := 0 to -1 + rowCount * colCount doĪButton.Parent := GridPanel1 //magic: place in the next empty cell Value := 100 / rowCount //have cells evenly distributed btw, cannot clear if there are controls, so first remove "old" controls above Procedure TForm1.CreateButtonGrid(const rowCount, colCount : integer) įor i := 0 to -1 + GridPanel1.ControlCount do Procedure TForm1.FormCreate(Sender: TObject) So, without further ado, here’s how to add controls to GridPanel dynamically: ![]() You’ll have to specify the SizeStyle for each cell and finally you have to somehow add a control to each cell. You’ll have to deal with RowCollection and ColumnCollection properties (to add or remove rows/columns). Say you do not know the number of rows or columns at design time, but you need to add controls to the grid panel dynamically where the number of rows/columns (/controls) changes. ![]() What if you need to dynamically add controls to grid panel at run-time? That’s all great when you know the design at design-time – and you know what number of controls you want to be hosted by the grid panel. ![]() What’s more you can even determine how each cell will be sized: will it have a fixed size, or a percentage of the grid size – so you can have controls nicely uniformly distributed in a grid. As you add more controls the grid will grow either by rows or columns being added automagically (or not, if the ExpandStyle poroperty is set to emFixedSize). Unlike standard TPanel, when you drop a control on a GridPanel it will be placed in the next available empty cell in the grid. To place controls on a grid panel you specify the number of rows and columns ( RowCollection and ColumnCollection properties) and simply drop a control on it. Delphi’s TGridPanel control is an ideal pick when you want to create grid-flow like user interface layout for your controls. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |