When i select in the designer a tab for example General and change in the properties the font size it will change only the size of the controls inside the tab but the name General will stay small.
I can't find where/how to change the General size.
Tab properties screenshot i changed the tab font size but the title General is still small. The property Text it's size not changed.
If you change the Font
size of the Tab
control then the font of the tab headers will change. And since Font is an ambient
property it will also get passed on to all contained controls.
To prevent this, best reset the font to the original size for each TabPage
.
In your screenshot you show us the effect of setting the Font
size not of the Tab
control but of a TabPage
only. This of course will not influence the tab headers..
I wanted to make the TabControl header font size adjustable in the UI, but was running into the problem that I couldn't change just the header size, without changing all the fonts in the tab. This is because of the ambient nature of the font properties in the child controls, as mentioned above.
My solution in the end was to first remove the ambient/inherited nature of the font in the child controls, using the following routine:
public static void ForceNonAmbientFont(System.Windows.Forms.Control.ControlCollection ctrls)
{
foreach (Control ctrl in ctrls)
{
if (ctrl.Controls != null) ForceNonAmbientFont(ctrl.Controls);
if (ctrl != null)
{
var fontFamilyName = ctrl.Font.FontFamily.Name;
var fontStyle = ctrl.Font.Style;
ctrl.Font = new Font(fontFamilyName, ctrl.Font.Size, fontStyle);
};
};
}
You then call this with the name of the TabControl you want to change the header font for. This then "locks" in all of the fonts for the children.
ForceNonAmbientFont(MyTabControl.Controls);
After that, you can then change the font of the TabControl without messing anything else up.
MyTabControl.Font = new System.Drawing.Font("Microsoft Sans Serif", size, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.