TabControl tab headings resize when changing font

家住魔仙堡 提交于 2020-01-01 19:12:49

问题


I have an application that changes the font of every control to SegoeUI when it is run in Vista. 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? (I have tried AutoSizeMode, but it only deals with a tab's width)

If not, what is the best way programmatically to resize the tabpage headings based on the font size?


回答1:


There is an ItemSize property on the tab control that you can set to change the size of the tabs themselves. 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. That can help you determine if you need to change the ItemSize property. Some rough code:

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


来源:https://stackoverflow.com/questions/349133/tabcontrol-tab-headings-resize-when-changing-font

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!