Winforms TabControl对齐问题 [英] Winforms TabControl alignment problems

查看:92
本文介绍了Winforms TabControl对齐问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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设置为Buttons,因为如果将其设置为Normal,按钮上的文本将消失.

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

更新:
当我将TabControl.Alignment设置为Bottom并将TabControl.Appearance设置为Normal时,按钮看起来是倒置的(橙色线应在下面)

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

当我将TabControl.Alignment设置为Bottom并将TabControl.Appearance设置为Buttons时,TabPage上没有用于放置控件的区域

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

推荐答案

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

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

这篇关于Winforms TabControl对齐问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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