bytecode77
bytecode77

Reputation: 14860

C# Remove padding from TabPages in Windows Forms

The tabpages have a padding between the border and the inside controls. Is there a way to remove this padding?

This is necessary as the TabControl will look bad if docked in parent container.

I tried some method overriding yet, but it didn't work.

Upvotes: 2

Views: 4235

Answers (1)

bytecode77
bytecode77

Reputation: 14860

I found out it can be achieved using WndProc:

public class TabControl2 : TabControl
{
    protected override void WndProc(ref Message m)
    {
        if (m.Msg == 0x1300 + 40)
        {
            RECT rc = (RECT)m.GetLParam(typeof(RECT));
            rc.Left -= 7;
            rc.Right += 7;
            rc.Top -= 2;
            rc.Bottom += 7;
            Marshal.StructureToPtr(rc, m.LParam, true);
        }
        base.WndProc(ref m);
    }
}

public struct RECT
{
    public int Left, Top, Right, Bottom;
}

Upvotes: 7

Related Questions