Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Winforms TabControl alignment problems

When I set TabControl alignment to Left or Right it leaves this huge space between tab buttons and tab page area. How to get rid of this useless space?

TabControl.Appearance is set to Buttons because if it is set to Normal the text on buttons disappear.

tabcontrol

UPDATE:
When i set TabControl.Alignment to Bottom and TabControl.Appearance to Normal buttons look inverted (orange line should be below)
tab control

When i set TabControl.Alignment to Bottom and TabControl.Appearance to Buttons, There is no area on TabPage to place controls
enter image description here

like image 872
SMUsamaShah Avatar asked Feb 07 '11 23:02

SMUsamaShah


1 Answers

This is a well-known problem with the XP visual style implementation for the native tab control, only tabs aligned to the top render properly. This bug hasn't been addressed until Windows 7. The workaround is to selectively turn off the style. 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 and change the Alignment property to your liking. It isn't going to look prettier than that.

using System;
using System.Windows.Forms;
using System.Runtime.InteropServices;

class FixedTabControl : TabControl {

    protected override void OnHandleCreated(EventArgs e) {
        SetWindowTheme(this.Handle, "", "");
        base.OnHandleCreated(e);
    }

    [DllImportAttribute("uxtheme.dll")]
    private static extern int SetWindowTheme(IntPtr hWnd, string appname, string idlist);
}
like image 88
Hans Passant Avatar answered Oct 21 '22 17:10

Hans Passant