How can I make WinForms TabPage header width fit it's title?

The native Windows tab control allows overriding the default minimum tab width. Sadly that capability is not exposed in the TabControl wrapper class. That's fixable though.

Add a new class to your project and paste the code shown below. Compile. Drop the new control from the top of the toolbox onto your form.

Up vote 2 down vote favorite share g+ share fb share tw.

Here is the problem. C# winforms width tabcontrol tabpage link|improve this question asked Jul 19 '11 at 9:44clumpter121110 58% accept rate.

The native Windows tab control allows overriding the default minimum tab width. Sadly that capability is not exposed in the TabControl wrapper class. That's fixable though.

Add a new class to your project and paste the code shown below. Compile. Drop the new control from the top of the toolbox onto your form.

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); }.

Thanks, Hans. I used your code without creating a class //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).

You need to measure the fonts. Try something like this: Dim tabPage As New TabPage Dim width As Integer = 0 Dim valueToMeasure As String = Dim g As Graphics = tabPage.CreateGraphics() width = CType(g. MeasureString(valueToMeasure, tabPage.

Font). Width, Integer) Probably add a bot extra on for padding (width = width +10) Edited: . Width = GetTabWidth() 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.

– clumpter Jul 19 '11 at 10:13 . Width = measured width – Richard Jul 19 '11 at 10:13 Please see my edit above – Richard Jul 19 '11 at 10:24 TabPage doesn't have width property. – clumpter Jul 19 '11 at 10:27 Sorry, Im used to KryptonNavigators!

Try... .Size. Width = GetTabWidth() – Richard Jul 19 '11 at 10:35.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions