The TExpander component is available in Delphi 10.4 Sydney and later versions. It is a control that allows you to expand or collapse a section of your user interface.
Here are the steps to use the TExpander component in Delphi:
- Add the TExpander component to your form by dragging it from the Component Palette onto the form in the Designer.
- Set the properties of the TExpander component as needed. For example, you can set the Text property to specify the text that will be displayed on the expander button.
- Use the Content property to specify the control that will be shown or hidden when the expander button is pressed. The Content property can be set to any control that is a child of the TExpander component.
- To respond to changes in the expander state, you can use the OnExpanded event or OnCollapsed event.
- You can use the Expanded property to get or set the state of the expander.
Here’s an example of how you might use a TExpander component in a Delphi program:
1 2 3 4 5 6 7 8 9 |
procedure TForm1.Expander1Expanded(Sender: TObject); begin ShowMessage(‘The expander is expanded.’); end; procedure TForm1.Expander1Collapsed(Sender: TObject); begin ShowMessage(‘The expander is collapsed.’); end; |
In this example, the OnExpanded and OnCollapsed events are handled by the Expander1Expanded and Expander1Collapsed procedures. These procedures display a message box accordingly.
You can also customize the appearance of the expander by setting the StyleLookup property to a custom style. Additionally, you can use the custom styles to make the expander look different in different states, like using different colors for expanded and collapsed states.
You can also use the Align property to specify where on the container the expander should be displayed, and use the Size property to set the size of the expander.
It’s also worth noting that, if you need to have a more complex expander in your application, you might consider using third-party libraries. Some of them have more advanced features like custom animations, different shapes and customizing the look and feel of the expander.
Leave a Reply