简体   繁体   English

更改字体时调整TabControl标签标题的大小

[英]TabControl tab headings resize when changing font

I have an application that changes the font of every control to SegoeUI when it is run in Vista. 我有一个应用程序,可以在Vista中运行时将每个控件的字体更改为SegoeUI。 It works fine, except for headings of tabpages (the buttons to click when switching from one tab to another). 除了选项卡标题(从一个选项卡切换到另一个选项卡时要单击的按钮)的标题之外,它都可以正常工作。

Tab page headings do not grow vertically to accommodate a larger font size, they always remain the same height. 选项卡页标题不会垂直增长以容纳较大的字体,它们始终保持相同的高度。

Is there a property that will allow the TabControl to handle this? 是否存在允许TabControl处理此属性的属性? (I have tried AutoSizeMode, but it only deals with a tab's width) (我尝试过AutoSizeMode,但它仅处理选项卡的宽度)

If not, what is the best way programmatically to resize the tabpage headings based on the font size? 如果没有,以编程方式根据字体大小调整标签页标题大小的最佳方法是什么?

There is an ItemSize property on the tab control that you can set to change the size of the tabs themselves. 选项卡控件上有一个ItemSize属性,您可以设置该属性来更改选项卡本身的大小。 Also, to help you out with getting the size of the text, there's a MeasureString() method on the Graphics object that will give you back a SizeF struct with the size of the given text. 另外,为了帮助您获取文本的大小,Graphics对象上有一个MeasureString()方法,该方法将为您提供具有给定文本大小的SizeF结构。 That can help you determine if you need to change the ItemSize property. 这可以帮助您确定是否需要更改ItemSize属性。 Some rough code: 一些粗略的代码:

            Graphics g = this.tabControl1.TabPages[0].CreateGraphics();
            SizeF s = g.MeasureString(this.tabControl1.TabPages[0].Text, this.tabControl1.TabPages[0].Font);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM