简体   繁体   English

调整文档停靠的DockContent中的停靠窗格选项卡条文本和按钮的大小

[英]Resize dock pane tab strip text and buttons in Document docked DockContent

I am refactoring a Windows Forms application to scale properly with high DPI settings. 我正在重构Windows窗体应用程序,以通过高DPI设置正确缩放。 This application uses DockPanelSuite library to dock some of its tools ( DockArea.DockLeft ) and the main view area ( DockArea.Document ). 此应用程序使用DockPanelSuite库来停靠其某些工具( DockArea.DockLeft )和主视图区域( DockArea.Document )。

My problem is that main view area tab strip width is often smaller than enclosed caption text width, as you can see here . 我的问题是,主视图区域的标签条宽度通常小于封闭的标题文本宽度,如您在此处看到的。 Also, when form is scaled (because moved between screens with differed DPI settings) tab strip buttons are not scaled properly (see here ). 同样,在缩放表单时(由于在具有不同DPI设置的屏幕之间移动),标签条按钮也无法正确缩放(请参见此处 )。

I've tried modifying Font size using these properties: 我尝试使用以下属性修改字体大小:

dockPanel1.Theme.Skin.DockPaneStripSkin.TextFont dockPanel1.Theme.Skin.AutoHideStripSkin.TextFont dockPanel1.Theme.Skin.DockPaneStripSkin.TextFont dockPanel1.Theme.Skin.AutoHideStripSkin.TextFont

But they do not scale the strip container, only the text inside it. 但是它们不缩放带状容器,仅缩放其中的文本。 What can I do to scale tab strip width and buttons in the correct way? 如何以正确的方式缩放标签条宽度和按钮?

First you should look at code that is used for scaling. 首先,您应该查看用于缩放的代码。 Obviously it scales tab headers vertical and horizontal but not it's text. 显然,它可以垂直和水平缩放tab headers ,但不能缩放文本。

There are two possible solutions to this: 有两种可能的解决方案:

  • Rewrite code used for scaling so it also get's tab font / tab page font and rescale it 重写用于缩放的代码,这样它也可以获得tab font / tab page font并重新缩放
  • Create custom extension method 创建自定义扩展方法

If you go for second method just simple create extension method look at TextRenderer class to measure free space and font size it should go there and then use tab.Font to change font on all tabPages at once or tabPage.Font to change it for each. 如果您使用第二种方法,则只需简单地创建扩展方法,看看TextRenderer类以测量可用空间和字体大小,然后应使用该tab.Font ,然后使用tab.Font一次更改所有tabPages上的字体,或使用tabPage.Font对其每个字体进行更改。

Then when you initialize everything just call this method yourTabControl.ResizeFonts(); 然后,当您初始化所有内容时,只需调用此方法yourTabControl.ResizeFonts();

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

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