2014-04-23 258 views
1

在我的表單中,我使用了tabcontrol。我想要隱藏標籤標題和邊框兩者。我可以做任何一個,如果我試圖隱藏標題,然後邊框變得可見。任何人都可以幫助我嗎?由於這裏是我的代碼:c#:如何刪除tabcontrol邊框?

public Form3() 
{ 
    InitializeComponent(); 
    this.NativeTabControl1 = new NativeTabControl(); 

    this.NativeTabControl1.AssignHandle(this.tabControl1.Handle); 

} 

private NativeTabControl NativeTabControl1; 

private class NativeTabControl : NativeWindow 
{ 
    protected override void WndProc(ref Message m) 
    { 
     if ((m.Msg == TCM_ADJUSTRECT)) 
     { 
      RECT rc = (RECT)m.GetLParam(typeof(RECT)); 
      //Adjust these values to suit, dependant upon Appearance 
      rc.Left -= 3; 
      rc.Right += 3; 
      rc.Top -= 3; 
      rc.Bottom += 3; 
      Marshal.StructureToPtr(rc, m.LParam, true); 
     } 
     base.WndProc(ref m); 
    } 

    private const Int32 TCM_FIRST = 0x1300; 
    private const Int32 TCM_ADJUSTRECT = (TCM_FIRST + 40); 
    private struct RECT 
    { 
     public Int32 Left; 
     public Int32 Top; 
     public Int32 Right; 
     public Int32 Bottom; 
    } 

    private void Form3_Load(object sender, EventArgs e) 
    { 
     //hides tabcontrol headers 
     tabControl1.Appearance = TabAppearance.Buttons; 
     tabControl1.ItemSize = new Size(0, 1); 
     tabControl1.SizeMode = TabSizeMode.Fixed; 
    } 
} 

回答

0

我通常會建議做這在XAML不是C#(我是一個WPF開發者)我相信你可以在C#做得一樣好來命名這兩個TabControl的,以及作爲每個選項卡本身。

tabControlName.BorderBrush = null; 
///^Gets rid of the TabControl's border. 

tabName1.Height = 0; 
tabName2.Height = 0; 
tabNameETC.Height = 0; 
///^Removes the tabs(headers) if you have the TabControl.TabStripPlacement set to left 
/// or right, then use the following instead: 

tabName1.Width = 0 
tabName2.Width = 0 
tabNameETC.Width = 0 
+0

對不起,它不起作用 – feather

+0

當我嘗試應用在執行第一行代碼後在TabControl上出現以下錯誤。 ('System.Windows.Forms.TabControl'不包含'BorderBrush'的定義) –

2

another thread on Stackoverflow,它提供了一些想法隱藏TabControl的標籤行中Windows窗體。
我最喜歡的是覆蓋WndProc並將Multiline屬性設置爲true

public partial class TabControlWithoutHeader : TabControl 
{ 
    public TabControlWithoutHeader() 
    { 
     if (!this.DesignMode) this.Multiline = true; 
    } 

    protected override void WndProc(ref Message m) 
    { 
     if (m.Msg == 0x1328 && !this.DesignMode) 
      m.Result = new IntPtr(1); 
     else 
      base.WndProc(ref m); 
    } 
} 

我測試了Windows 8.1上的代碼,並沒有看到選項卡和邊界線。所以我認爲你不需要使用像你這樣的代碼。

+0

適用於Windows 7. Thx! – Mihai