C# Remove padding from TabPages in Windows Forms

Go To StackoverFlow.com

2

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.

2012-04-04 20:05
by bytecode77
possible duplicate of How can I remove the border padding on container controls in WinForms?Justin Pihony 2012-04-04 20:08
I'm not sure about the padding but can't you make the outer background/border of the tabcontrol the same as the parent container so it blends in. (ie. border = none - Kyra 2012-04-04 20:08
@JustinPihony I tried the code in "This answer" link and it gave me a win2k style TabControl. With "Explorer" as parameter, there were no changes at all. Kyra: TabControl has no Border property and the Border of TabPage is set to None by default - bytecode77 2012-04-04 20:32


5

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;
}
2012-04-20 08:12
by bytecode77
This was going in the right direction but was removing the border. Further there was still a white padding at the top. This produced the cleanest results for me: http://stackoverflow.com/a/7785745/92051 - Knickedi 2013-10-13 17:27
Ads