2013-08-01 57 views
3

我正在創建一個Windows C#/ .NET應用程序,我試圖使用外觀設置爲按鈕的TabControl。我希望標籤只有圖片,沒有文字。但是,我得到了一堆上的每個按鈕,我想它的右側微胖的擺脫:Windows TabControl外觀=按鈕,在右邊獲得寬邊距

enter image description here
我能夠通過減少字體大小,以減少右頁邊距1,但它仍然比左側寬幾個像素,並且看起來有點笨拙。有沒有更好的辦法?

+1

微軟幾乎沒有作出努力,使這項工作。 DrawMode.OwnerDrawFixed可能是使其使用ItemSize集合並將SizeMode設置爲Fixed的唯一方法。 – LarsTech

+0

圖像是簡單的左對齊,並且標籤寬度不能太小,所以最終會在圖像右側留出額外的空間。考慮一個更合適的(更廣泛的)圖像或ownerdraw。 –

回答

1

嘗試這個

public frmForm() 
{ 
    InitializeComponent(); 
    tabControl1.Appearance = TabAppearance.Buttons; 
    tabControl1.DrawMode = TabDrawMode.OwnerDrawFixed; 
    tabControl1.DrawItem += new DrawItemEventHandler(tabControl1_DrawItem); 
} 

private void tabControl1_DrawItem(object sender, DrawItemEventArgs e) 
{ 
    //Load the image 
    Image img = Image.FromFile(String.Format("{0}\\{1}.jpg",Application.StartupPath,tabControl1.TabPages[e.Index].Name)); 
    //Resize image 
    img = new Bitmap(img, e.Bounds.Size); 
    //Draw on Tab Button 
    e.Graphics.DrawImage(img, e.Bounds.Location); 
} 

enter image description here