2012-04-04 42 views
2

這些標籤在邊框和內部控件之間有一個填充。有沒有辦法刪除這個填充?C#從Windows窗體的TabPages中刪除填充

這是必要的,因爲如果停靠在父容器中,TabControl看起來很糟糕。

我試過一些方法覆蓋,但它沒有奏效。

+0

可能重複[?我怎樣才能刪除的Win​​Forms上的容器控件邊框的填充(http://stackoverflow.com/questions/4968267/how-can-i-remove-the-border-padding-on-container-controls-in-winforms) – 2012-04-04 20:08:53

+0

我不確定填充,但不能使tabcontrol的外部背景/邊框相同作爲父容器,所以它融入。(即。border = none) – Kyra 2012-04-04 20:08:54

+0

@JustinPihony我試着在「這個答案」鏈接中的代碼,它給了我一個win2k風格的TabControl。以「Explorer」作爲參數,根本沒有任何變化。 Kyra:TabControl沒有Border屬性,默認情況下TabPage的Border設置爲None。 – bytecode77 2012-04-04 20:32:47

回答

5

我發現它可以實現使用WndProc

public class TabControl2 : TabControl 
{ 
    protected override void WndProc(ref Message m) 
    { 
     if (m.Msg == 0x1300 + 40) 
     { 
      RECT rc = (RECT)m.GetLParam(typeof(RECT)); 
      rc.Left -= 7; 
      rc.Right += 7; 
      rc.Top -= 2; 
      rc.Bottom += 7; 
      Marshal.StructureToPtr(rc, m.LParam, true); 
     } 
     base.WndProc(ref m); 
    } 
} 

public struct RECT 
{ 
    public int Left, Top, Right, Bottom; 
} 
+0

這是正確的方向,但是刪除了邊界。此外,頂部還有一個白色的填充物。這爲我產生了最乾淨的結果:http://stackoverflow.com/a/7785745/920511 – Knickedi 2013-10-13 17:27:59