2011-07-19 14 views

Odpowiedz

10

Natywna kontrola zakładka Windows umożliwia przesłonięcie domyślnej minimalnej szerokości karty. Niestety ta możliwość nie jest widoczna w klasie pakowania TabControl. Można to naprawić. Dodaj nową klasę do swojego projektu i wklej poniższy kod. Skompilować. Rzuć nową kontrolę z góry przybornika na formularz.

using System; 
using System.Windows.Forms; 

class MyTabControl : TabControl { 
    protected override void OnHandleCreated(EventArgs e) { 
     base.OnHandleCreated(e); 
     // Send TCM_SETMINTABWIDTH 
     SendMessage(this.Handle, 0x1300 + 49, IntPtr.Zero, (IntPtr)10); 
    } 
    [System.Runtime.InteropServices.DllImport("user32.dll")] 
    private static extern IntPtr SendMessage(IntPtr hWnd, int msg, IntPtr wp, IntPtr lp); 
} 
0

Musisz zmierzyć czcionek.

Spróbuj czegoś takiego:

Dim tabPage As New TabPage 
Dim width As Integer = 0 
Dim valueToMeasure As String = <Your title Here> 
Dim g As Graphics = tabPage.CreateGraphics() 

width = CType(g.MeasureString(valueToMeasure, tabPage.Font).Width, Integer) 

Prawdopodobnie dodać bota na Extra dla obicia (szerokość = szerokość +10)

Zmieniano:

<tab>.width = GetTabWidth(<Title>) 

Private Function GetTabWidth (Byval title as String) as Integer 

    Dim widthValue as Integer = 10 'Padding (Optional) 

    Dim tabPage as New tabPage 
    Dim g as Graphics = tabPage.CreateGraphics() 

    widthValue += Ctype(g.measureString(title, tabPage.Font).Width, Integer) 

    Return widthValue 

End Function 
+1

Dobra, mam to, co dalej? – clumpter

+0

.width = zmierzona szerokość –

+0

Proszę zobaczyć moją edycję powyżej –

3

Dzięki, Hans. Użyłem twojego kodu bez tworzenia klasy

//InitializeComponent 
this.tabPresentations.HandleCreated += new System.EventHandler(TabControl_HandleCreated); 

void TabControl_HandleCreated(object sender, System.EventArgs e) 
{ 
    // Send TCM_SETMINTABWIDTH 
    SendMessage((sender as TabControl).Handle, 0x1300 + 49, IntPtr.Zero, (IntPtr)4); 
} 
[System.Runtime.InteropServices.DllImport("user32.dll")] 
private static extern IntPtr SendMessage(IntPtr hWnd, int msg, IntPtr wp, IntPtr lp); 
Powiązane problemy