Jandy Jandy - 2 months ago 12
C# Question

Increase Width and Height of Headers in TabControl

I don't like

, they look ugly. So I'm creating my own custom drawn
. I have some problems with header height. my control look like below:

enter image description here

Control constructor:

this.SetStyle(ControlStyles.UserPaint, true);
this.SetStyle(Conbut trolStyles.OptimizedDoubleBuffer, true);
SetStyle(ControlStyles.AllPaintingInWmPaint, true);
this.DrawMode = TabDrawMode.OwnerDrawFixed;


var g = pevent.Graphics;
var Count = this.TabCount - 1;
int Offset = 2;
int index = 0;
foreach (TabPage itemtab in this.TabPages)
//SizeF sz = g.MeasureString(itemtab.Text, this.Font);
var tabrect = this.GetTabRect(index);
var headerrect = new Rectangle(tabrect.Left + Offset, tabrect.Y, tabrect.Width, tabrect.Height);
DrawRoundedRectangle(g, Headerbrush, headerrect, 3);
g.DrawString(itemtab.Text, this.Font, textbrush, headerrect, str);
if (index < Count) index++;

I tried to add this line:

this.ItemSize = new Size(100, 30);

But width returns wrong value when changing the font's size or the text of header.

enter image description here

Is there a way increase widths and height of header?


To have larger tabs you can use either of these options:

  1. The control automatically provide enough room for text t be drawn using the Font of TabControl. You can simply add extra room, using Padding property. The Padding property specifies the amount of space around each item on the control's tab pages.

  2. You can set ItemSize to a larger size and set SizeMode to Fixed.

ItemSize.Width doesn't have any impact on header width, unless you set SizeMode to Fixed. It's the reason for unexpected width which you see in your control.