2013-12-10 91 views
0

VB.Net,TabStrip控件,如何定位在一個TabControl vb.net標籤

標籤是左對齊或右和頂部或底部

我需要從我自己的位置在最前面的開始選項卡Tab控件

與Internet Explorer類似,選項卡在HTTP地址框之後開始,但它將覆蓋整頁和左對齊= 0。

+0

Hmya,而Internet Explorer *不*使用一個TabControl,它的標籤是完全自定義繪製。您可以通過不使用標籤頁來模擬類似的東西,只需使TabControl的高度足以顯示標籤即可。 –

回答

0

要顯示右對齊的標籤

  1. 一個的TabControl添加到您的窗體。

  2. 設置對齊屬性爲

  3. 設置SizeMode屬性固定,讓所有標籤都是相同的寬度。

  4. 項目大小屬性設置爲選項卡的首選固定大小。請記住ItemSize屬性的行爲與標籤在頂部一樣,儘管它們是右對齊的。因此,爲了使選項卡變寬,您必須更改高度屬性,並且爲了使它們更高,您必須更改寬度屬性。

    在下面的代碼示例,寬度設置爲25和高度被設定爲150

  5. 設置DrawMode屬性OwnerDrawFixed

  6. 定義處理DrawItem事件TabControl的呈現由左到右的文本。

    C#

    public Form1() 
    { 
        // Remove this call if you do not program using Visual Studio. 
        InitializeComponent(); 
    
        tabControl1.DrawItem += new DrawItemEventHandler(tabControl1_DrawItem); 
    } 
    
    private void tabControl1_DrawItem(Object sender, System.Windows.Forms.DrawItemEventArgs e) 
    { 
        Graphics g = e.Graphics; 
        Brush _textBrush; 
    
        // Get the item from the collection. 
        TabPage _tabPage = tabControl1.TabPages[e.Index]; 
    
        // Get the real bounds for the tab rectangle. 
        Rectangle _tabBounds = tabControl1.GetTabRect(e.Index); 
    
        if (e.State == DrawItemState.Selected) 
        { 
         // Draw a different background color, and don't paint a focus rectangle. 
    
         _textBrush = new SolidBrush(Color.Red); 
         g.FillRectangle(Brushes.Gray, e.Bounds); 
        } 
        else 
        { 
         _textBrush = new System.Drawing.SolidBrush(e.ForeColor); 
         e.DrawBackground(); 
        } 
    
        // Use our own font. 
        Font _tabFont = new Font("Arial", (float)10.0, FontStyle.Bold, GraphicsUnit.Pixel); 
    
        // Draw string. Center the text. 
        StringFormat _stringFlags = new StringFormat(); 
        _stringFlags.Alignment = StringAlignment.Center; 
        _stringFlags.LineAlignment = StringAlignment.Center; 
        g.DrawString(_tabPage.Text, _tabFont, _textBrush, _tabBounds, new StringFormat(_stringFlags)); 
    
相關問題