Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Windows TabControl with Appearance=Buttons, getting wide margins on the right

I'm creating a Windows C#/.NET app, and I'm trying to use a TabControl with the Appearance set to Buttons. I want the tabs to have images only, no text. However, I'm getting a bunch of extra padding on the right side of each button, which I'd like to get rid of:

enter image description here
I am able to reduce the right margin by reducing the font size to 1, but it's still a few pixels wider than the left side, and it seems a bit kludgy. Is there a better way?

like image 887
Karl von L Avatar asked Nov 30 '25 21:11

Karl von L


1 Answers

Try This

public frmForm()
{
     InitializeComponent();
     tabControl1.Appearance = TabAppearance.Buttons;
     tabControl1.DrawMode = TabDrawMode.OwnerDrawFixed;
     tabControl1.DrawItem += new DrawItemEventHandler(tabControl1_DrawItem);
}

private void tabControl1_DrawItem(object sender, DrawItemEventArgs e)
{
    //Load the image
    Image img = Image.FromFile(String.Format("{0}\\{1}.jpg",Application.StartupPath,tabControl1.TabPages[e.Index].Name));
    //Resize image
    img = new Bitmap(img, e.Bounds.Size);
    //Draw on Tab Button
    e.Graphics.DrawImage(img, e.Bounds.Location);
}

enter image description here

like image 134
Shell Avatar answered Dec 03 '25 06:12

Shell



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!