2011-02-07 38 views
4

當我將TabControl對齊設置爲LeftRight時,它在標籤頁按鈕和標籤頁區域之間留下了巨大的空間。如何擺脫這個無用的空間?Winforms TabControl對齊問題

TabControl.Appearance設置爲Buttons,因爲如果它設置爲Normal,按鈕上的文本消失。

tabcontrol

UPDATE:
當我設置TabControl.AlignmentBottomTabControl.AppearanceNormal按鈕看起來反轉(橙色線應該低於)
tab control

在i設定TabControl.AlignmentBottomTabControl.AppearanceButtonsTabPage上沒有放置控件的區域
enter image description here

+0

有趣。我剛剛在C#2010 Express中嘗試了這一點,並且看到您在此處顯示的行爲。但是,當我將`Appearance`更改爲`Normal`時,一切看起來很正常,文本仍然可見。當處於「正常」模式時,您是否看到過文本(無論是在設計階段還是在運行階段)? – Pwninstein 2011-02-07 23:59:48

+0

不,在左右對齊時,正常模式下無文字。這就是我改變模式的原因 – SMUsamaShah 2011-02-08 00:19:27

回答

5

這是一個衆所周知的XP本機選項卡控件的可視化樣式實現問題,只有選項卡對齊頂部呈現正確。直到Windows 7才解決該錯誤。解決方法是有選擇地關閉樣式。爲您的項目添加一個新類並粘貼下面顯示的代碼。編譯。將新控件從工具箱的頂部放到窗體上,並根據自己的喜好更改「對齊」屬性。它不會看起來更漂亮。

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