views:

231

answers:

2

I have a tab control where I'm using user painting to remove flickering. It's rendering fine in terms of flicker removal, but the tab widths are not right. There is a large amount of padding around the text that gets bigger as the length of the text on the tab increases. It's like the width of the tab is based on a font that is larger than the one that is being drawn. I have tried changing the size of the font on the tab control, but that has no effect on the tab widths.

How does the tab control determine the widths of the tabs? Is there something I can override so that I can supply the tab widths to the tab control?

A: 

Have you tried to enable double buffering to remove the flicker before using custom painting?

Just try to call this function in your control constructor and see how it works:

private void EnableDoubleBuffering()
{
   this.SetStyle(ControlStyles.DoubleBuffer | 
      ControlStyles.UserPaint | 
      ControlStyles.AllPaintingInWmPaint,
      true);
   this.UpdateStyles();
}
Claudiu
Setting UserPaint specifies that the control must be drawn by the OnPaint method on the subclass. Without an OnPaint method, the tabs are not drawn. Just setting DoubleBuffer does not remove the flickering.
A: 

The TabControl has a property called ItemSize which is indeed used to inform the TabControl as to the size of its tabs.

Ian