2009-02-20 89 views
1

我們有一個窗體,它在選項卡控件的標籤頁中顯示媒體項目,我正在實現一項功能,允許用戶將標籤頁彈出到自己的窗體中。如何獲得一個看起來像沒有標籤的TabControl的控件?

但是,當我將媒體播放器添加到窗體而不是TabPage時,背景會從標籤頁的漸變填充切換到父窗體的純色SystemColors.Control背景。我需要將媒體播放器添加到與TabControl具有相同背景的控件,但不在頂部顯示選項卡。我嘗試將媒體播放器添加到TabControl的控件集合中,但這只是引發異常。

如何獲得一個看起來像沒有標籤的TabControl的控件?我應該不斷嘗試將媒體播放器添加到TabControl,還是應該嘗試使用自定義繪製的背景編寫一個Panel?如果是後者,我如何確保它能適用於所有可能的主題?

回答

3

感謝亨克 - 我最終與去:

protected override void OnPaintBackground(PaintEventArgs e) 
{ 
    if (TabRenderer.IsSupported && Application.RenderWithVisualStyles) 
    { 
     TabRenderer.DrawTabPage(pe.Graphics, this.ClientRectangle); 
    } 
    else 
    { 
     base.OnPaintBackground(pe); 
     ControlPaint.DrawBorder3D(pe.Graphics, this.ClientRectangle, Border3DStyle.Raised); 
    } 
} 
0

嘗試創建自己的客戶用戶控件

+0

OK ..我怎麼做,看起來就像一個沒有標籤一個TabControl? – Simon 2009-02-20 10:14:18

+0

沒有選項卡的TabControl,是不是隻是一個面板? – Svish 2009-02-20 10:39:08

3

的問題似乎是對UseVisbleBackgroundStyle。僅AFAIK按鈕和TabPages具有此屬性。

下面是一個非常骯髒的黑客,只是爲了讓你開始:

1)從小組派生customControl,並添加「使用System.Windows.Forms.VisualStyles;」

2)添加以下代碼

//warning: incomplete, add error checking etc 
private readonly VisualStyleElement element = VisualStyleElement.Tab.Body.Normal; 
public bool UseVisbleBackgroundStyle { get; set; } 

protected override void OnPaint(PaintEventArgs pe) 
{ 
    if (UseVisbleBackgroundStyle) 
    { 
     var x = new VisualStyleRenderer(element);       
     x.DrawBackground(pe.Graphics, this.ClientRectangle); 
    } 
    else 
    { 
     base.OnPaint(pe); 
    } 
} 
0

這個答案是從另一個answer site修改。它的做法相當乾淨。

在包含選項卡控件的窗口中加載事件,請嘗試:

// TabControl is the name of the tab control in this window. 
TabControl.Appearance = TabAppearance.FlatButtons; 
TabControl.Multiline = false; 
TabControl.SizeMode = TabSizeMode.Fixed; 
TabControl.ItemSize = new Size(0,1); 

// The tabs are now gone. Select the panel you want to display 
TabControl.SelectTab("InProgressTab"); 
相關問題