Team LiB
Previous Section Next Section

Ambient Properties

The last thing I want to talk about in this chapter is the ambient properties. Did you even know these existed? There is no such property as "Ambient" on any control that you will find.

Try this. Increase the font size on the last form you made. You should see the font size on all the form's controls also increases. The Font property is an ambient property.

Most controls take some of their properties from the parent control. Here is what happens with ambient properties. If certain properties on a control are not explicitly set, that control will try to get its value for that property from the parent control. Once the property has been set, you can change the parent property and the control's property will not change. Try this:

  1. Change the font on one of the buttons to be bold.

  2. Set this Font property back to normal on the button.

  3. Change the Font property on the form to be bold.

All the controls on the form change to bold except the button you just worked with. This is because you have already explicitly set this property on this control.

If the control has no parent, then it tries to set the property via the Site property. In other words, it tries to find some other control to ask what it should do.

I said that there was no such property as "Ambient" on a control. There is, however, an AmbientProperties class. This class defines the following properties as ambient:

So why include this class in the Framework? You will want to inherit from this class if you make your own control. Just like writing a program that behaves according to a preconceived set of rules, your control will also be "expected" to have these ambient properties. Perhaps you should even add more.


Team LiB
Previous Section Next Section