更改字体时,TabControl 选项卡标题会调整大小 [英] TabControl tab headings resize when changing font

查看:40
本文介绍了更改字体时,TabControl 选项卡标题会调整大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个应用程序,它在 Vista 中运行时将每个控件的字体更改为 SegoeUI.它工作正常,除了标签页的标题(从一个标签切换到另一个标签时要单击的按钮).

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.

是否有允许 TabControl 处理此问题的属性?(我试过 AutoSizeMode,但它只处理标签的宽度)

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?

推荐答案

选项卡控件上有一个 ItemSize 属性,您可以设置该属性来更改选项卡本身的大小.此外,为了帮助您获取文本的大小,Graphics 对象上有一个 MeasureString() 方法,它将返回一个具有给定文本大小的 SizeF 结构.这可以帮助您确定是否需要更改 ItemSize 属性.一些粗略的代码:

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);

这篇关于更改字体时,TabControl 选项卡标题会调整大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆