Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

How can i make WinForms TabPage header width fit it's title? Here is the problem.

enter image description here

like image 317
clumpter Avatar asked Jul 19 '11 09:07

clumpter


1 Answers

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);
}
like image 80
Hans Passant Avatar answered Sep 28 '22 08:09

Hans Passant