User Rating: 3 / 5

Star ActiveStar ActiveStar ActiveStar InactiveStar Inactive
 

In the Enable and Disable Groups of Controls article we discussed how you can enable or disable group of controls by setting the parent control’s Enable property.

Now we will look at other properties that have a similar trickle down effect, but work fundamentally in a different fashion. For example, if you change the font of the Form control, you may notice that all the controls within the form change their fonts accordingly. These trickle down properties are known as ambient properties. Ambient properties are properties that if not individually set, take their value from the parent control.

There are four common ambient properties:

Cursor, Font, BackColor, ForeColor

To illustrate how ambient properties work, consider the following example:

A sample form contains two buttons and various other controls. When button1’s Font property is changed from the default, it uses the new font instead of inheriting the font of the parent form:

sample form properties(Change the font of the control by using the Properties Pane)

On the other hand, button2 is using the default font value and thus inherits the parent form’s font setting:

buttons with ambient properties

Tip The Properties Panel indicates a property with a non-default value by displaying its value in bold text:

Properties panel with default values properties panel with custom properties

Leaving the default value for the Font property on all the child controls makes it easy to change all the fonts by setting the form’s Font property to the desired font. Since the BackColor and ForeColor properties are also ambient properties, it makes it easy to theme the controls without having to alter each control’s properties individually. For example, when the form’s ForeColor property is set to Red, all the child controls follow suit (with the exception of the sample label, which has a preset ForeColor):

Form with default properties on child controls

Tip You can use panel and groupbox controls to set the fonts of specific groups of controls.

As you can see, ambient properties make it easier to style a large number of controls within the form without having to alter the controls individually; at the same time allowing you to customize the look of individual controls if needed.

You can download the Ambient Properties Sample here.

If you have questions about our products, please post in our support forum.
For licensed customers, use the forum associated with your product in our Product Support Forums for Registered Customers.
For users of trial versions, please post in our Former and Future Customers - Questions forum.
Copyright © 2024 SAPIEN Technologies, Inc.