المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : Tabcontrol flicker



C# Programming
03-31-2010, 08:02 PM
Hi,

I've got a form with a gradient background. On that form I places a tabcontrol. But when I a hover a tab of the tabcontrol, the tab starts flickering a lot. Is there any way to stop this flicker?

I have already found some solutions. One of them is to create a custom control which inherits from System.Windows.Forms.Tabcontrol.
I dit this and the flicker is gone, but when I use the following code, the font on my tabs isn't the default font like the rest of my form.

public class DoubleBufferedTabControl : TabControl
{
private System.Drawing.Bitmap buffer;
public DoubleBufferedTabControl()
{
this.SetStyle(ControlStyles.UserPaint | ControlStyles.DoubleBuffer | ControlStyles.AllPaintingInWmPaint, true);
}
protected override void OnPaint(PaintEventArgs e)
{
//Todo : lettertype overnemen van form
this.SetStyle(ControlStyles.UserPaint, false);
base.OnPaint(e);
System.Drawing.Rectangle o = e.ClipRectangle;
System.Drawing.Graphics.FromImage(buffer).Clear(System.Drawing.SystemColors.Control);
if (o.Width > 0 && o.Height > 0)
DrawToBitmap(buffer, new System.Drawing.Rectangle(0, 0, Width, o.Height));
e.Graphics.DrawImageUnscaled(buffer, 0, 0);
this.SetStyle(ControlStyles.UserPaint, true);
}

protected override void OnResize(EventArgs e)
{
base.OnResize(e);
buffer = new System.Drawing.Bitmap(Width, Height);
}
}

So if there is no easy way to stop this flicker, how can i get the font on my tabs just like the font of the rest of my form?