XtraLayoutControl – Creating and Customizing Layout Items
In this lesson, I’ll show you how to arrange controls within a form, using the XtraLayoutControl. This control provides advanced capabilities for creating, customizing and supporting the layout of controls within forms.
Let’s take a look at design-time.
- First of all, I’ll drop the layout control onto a form, and make it occupy the entire form’s area.
- Then, I drop different controls onto the layout control.
- For this demo, I shall use a TextEdit control, a PictureEdit control, a MemoEdit control, and finally, a DataNavigator.
- Controls can only reside within the Layout Control with the help of Layout Items, the basic blocks of the layout.
- When a control is dropped onto the Layout Control, a layout item which holds it, is automatically created.
- Now, I’ll re-arrange the layout items.
- I select the layout item, one at a time, and change their location within the layout control using drag and drop.
- And I’m done.
- The next step that I’ll show you, will be customizing the Layout Items.
- Layout Items can display a label, which enables a description to be added to the control.
- I’ll select the first layout item, and I’ll change its label’s default text to “Category Name”.
- Now, I’ll specify the description for the next layout item.
- I want this label to be displayed at the item’s top.
- To do this, I invoke the item’s context menu, and select “Top”.
- As for the item that contains the PictureEdit, I’ll hide its label completely.
- I can resize a couple of items.
- And I’m done.
- Notice that when I resize the form, all the controls are proportionally resized.
- Now, let’s lock the size of the PictureEdit.
- To do this, I create an empty space item, and locate it below.
- Then, I resize the layout item to the desired shape, and size, and lock it.
- Next time, when the form is resized, the size of the PictureEdit, won’t be changed.
- Finally, I’ll bind all of the controls to the data source providing that it has already been created and is customized.
- I’ll bind the TextEdit to the “Category Name” field,
- The MemoEdit to the “Description” field,
- The PictureEdit to the “Picture” field,
- And finally, I can bind the DataNavigator to the Data Source itself, to enable navigation through the records.
- Now I can run the application to see the results.
- As I said before, when I resize the form, all the controls except the PictureEdit are automatically resized, and no control overlaps another one.
- The Layout Control also enables the form’s layout to be customized at runtime.
- For this purpose, I can invoke the customization form.
- While this form is visible, I can modify the form’s layout.
- I can hide layout items, make the hidden items visible, and I can unlock the layout item that contains the PictureEdit.
- And I’m done.
- I can close the customization form, and continue on working.