Amro
Amro

Reputation: 1588

Windows form, stop child controls from inheriting Font of Form/GroupBox/Parent

is there a way to stop any control that has a font property from automatically inherit the font properties from the container control, like the Panel, GroupBox and Form.

i tried setting the AutoScaleMode to None on the container but without anyluck.

any suggestions?

Upvotes: 3

Views: 2482

Answers (1)

downeyt
downeyt

Reputation: 1306

Font, ForeColor, BackColor and Cursor are ambient properties, meaning that if they are not set, then they inherit from the parent container.

If the control sets the Font property, then the ambient font will not be used. If the control does not set the Font property, then it inherits from the parent container.

The ambient property is set in the base control class, like Label. The control defines Font as an ambient value. The only way to disable it is to override the Font property so it is not ambient. You could create new control classes, like MyLabel, that extend the Windows Forms Label class and then override the Font property so it is not ambient. Once the app is built, the MyLabel class can be dragged from the toolbox into the form designer.

I do not see the utility of disabling the ambient font. If the container has gone to the trouble to change the font, under which conditions is it favorable to leave the font as the one that Windows picks, which has nothing to do with the current theme set by the user?

Upvotes: 3

Related Questions