Winforms TabControl对齐问题

发布于 2024-10-16 05:27:16 字数 740 浏览 12 评论 0原文

当我将 TabControl 对齐设置为 LeftRight 时,它会在选项卡按钮和选项卡页面区域之间留下巨大的空间。如何摆脱这个无用的空间?

TabControl.Appearance 设置为 Buttons,因为如果将其设置为 Normal,按钮上的文本就会消失。

tabcontrol

更新:
当我将 TabControl.Alignment 设置为 Bottom 并将 TabControl.Appearance 设置为 Normal 按钮看起来是倒置的(橙色线应该是如下)
tab control

当我将 TabControl.Alignment 设置为 Bottom 和 < code>TabControl.Appearance 到 ButtonsTabPage 上没有放置控件的区域
在此处输入图像描述

When I set TabControl alignment to Left or Right it leaves this huge space between tab buttons and tab page area. How to get rid of this useless space?

TabControl.Appearance is set to Buttons because if it is set to Normal the text on buttons disappear.

tabcontrol

UPDATE:
When i set TabControl.Alignment to Bottom and TabControl.Appearance to Normal buttons look inverted (orange line should be below)
tab control

When i set TabControl.Alignment to Bottom and TabControl.Appearance to Buttons, There is no area on TabPage to place controls
enter image description here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

離人涙 2024-10-23 05:27:16

这是本机选项卡控件的 XP 视觉样式实现中的一个众所周知的问题,只有与顶部对齐的选项卡才能正确呈现。这个错误直到 Windows 7 才得到解决。解决方法是有选择地关闭该样式。将新类添加到您的项目中并粘贴下面所示的代码。编译。将新控件从工具箱顶部拖放到窗体上,然后根据您的喜好更改 Alignment 属性。它看起来不会比那更漂亮。

using System;
using System.Windows.Forms;
using System.Runtime.InteropServices;

class FixedTabControl : TabControl {

    protected override void OnHandleCreated(EventArgs e) {
        SetWindowTheme(this.Handle, "", "");
        base.OnHandleCreated(e);
    }

    [DllImportAttribute("uxtheme.dll")]
    private static extern int SetWindowTheme(IntPtr hWnd, string appname, string idlist);
}

This is a well-known problem with the XP visual style implementation for the native tab control, only tabs aligned to the top render properly. This bug hasn't been addressed until Windows 7. The workaround is to selectively turn off the style. Add a new class to your project and paste the code shown below. Compile. Drop the new control from the top of the toolbox onto your form and change the Alignment property to your liking. It isn't going to look prettier than that.

using System;
using System.Windows.Forms;
using System.Runtime.InteropServices;

class FixedTabControl : TabControl {

    protected override void OnHandleCreated(EventArgs e) {
        SetWindowTheme(this.Handle, "", "");
        base.OnHandleCreated(e);
    }

    [DllImportAttribute("uxtheme.dll")]
    private static extern int SetWindowTheme(IntPtr hWnd, string appname, string idlist);
}
各自安好 2024-10-23 05:27:16

Microsoft 文档与此问题相关的备注

当 Alignment 属性设置为 Left 或 Right 时,多行
属性自动设置为 true。

当您将 Appearance 属性设置为 FlatButtons 时,它仅出现
当 Alignment 属性设置为 Top 时也是如此。否则,
外观属性显示就像设置为“按钮”值一样。

当您将 Appearance 属性设置为 Buttons 时,还必须设置
将 Alignment 属性设置为 Top,以便按钮正确显示。

注意

当您将 Appearance 属性设置为 Buttons 时,还必须设置
将 Alignment 属性设置为 Top,以便显示选项卡页内容
正确。此外,当启用视觉样式时,
Alignment 属性设置为 Top 以外的值,选项卡内容
可能无法正确渲染。

Microsoft documentation Remarks related to this issue

When the Alignment property is set to Left or Right, the Multiline
property is automatically set to true.

When you set the Appearance property to FlatButtons, it only appears
as such when the Alignment property is set to Top. Otherwise, the
Appearance property displays as if set to the Buttons value.

When you set the Appearance property to Buttons, you must also set the
Alignment property to Top so that the buttons display correctly.

Note

When you set the Appearance property to Buttons, you must also set the
Alignment property to Top so that the tab page contents display
correctly. Additionally, when visual styles are enabled, and the
Alignment property is set to a value other than Top, the tab contents
may not render correctly.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文