Jandy Jandy - 1 year ago 171
C# Question

tabcontrol increase height of header

I don't like tabcontrol.They look ugly.I'm creating my own custom tabcontrol.I'm having 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;

And OnPaintBackground:

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 height of header?

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download