TabControl flicker issue

  • Thread starter Thread starter aagarwal8
  • Start date Start date
A

aagarwal8

Hi,

I have a very simple form containing a TabControl with 2 TabPages.
The
Dock property for TabControl is set to Fill. TabPage1 contains a
TreeView with some nodes. Tabpage2 is currently blank.


The problem is when i resize the Form, lot of flickering happens. (I
have set the windows appearance to Show the contents of window while
resizing).


Any help in this regard is appreciated.


Thanks,
Ankit!!
 
You could Inherit TabControl and set it's DoubleBuffered property to true.

Alternatively, use one of my TabControls instead.

On my downloads page you will find two tabcontrols.
http://www.dotnetrix.co.uk/controls.html

The first one (TabControlEx) is written for framework 1.1 and works well so
long as you don't want a mirrored TabControl.

The second one was written specifically for framework 2.0 and has no
problems with mirroring. This doesn't have all the features of TabControlEx,
but it's an improvement on the standard TabControl.
 
Hi Mick,

I downloaded the control but the flickering issue still persists.

The contents of the TreeView flicker a lot when i resize the form (on
which i have docked the TabControl)

Any suggestions?

Regards,
Ankit!!
 
Hi Ankit,

If you're going to be using Windows XP or Vista then you may have a simple
solution as described by Hans Passant in the following thread:
http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=2044742&SiteID=1

Other than that you'll probably have to use some sort of hack like the
following:

\\\
private void Form1_ResizeBegin(object sender, EventArgs e)
{
if (this.tabControl1.SelectedTab == this.tabPage1)
{
this.treeView1.Dock = DockStyle.None;
this.treeView1.Anchor = AnchorStyles.Left | AnchorStyles.Top |
AnchorStyles.Right | AnchorStyles.Bottom;
this.Controls.Add(this.treeView1);
this.treeView1.Location =
this.tabControl1.PointToScreen(Point.Empty);
Rectangle rc = this.tabControl1.DisplayRectangle;
rc.Width -= this.tabControl1.Margin.Horizontal;
rc.Height -= this.tabControl1.Margin.Vertical;
rc.Offset(this.tabControl1.Location);
rc.Offset(this.tabControl1.Margin.Left,
this.tabControl1.Margin.Top);
this.treeView1.SetBounds(rc.Left,rc.Top,rc.Width,rc.Height);
this.treeView1.BringToFront();
}
}

private void Form1_ResizeEnd(object sender, EventArgs e)
{
if (!this.tabPage1.Controls.Contains(this.treeView1))
{
this.tabPage1.Controls.Add(this.treeView1);
this.treeView1.Dock = DockStyle.Fill;
}
}

///
 
Thanks a bunch Mick...

Your hack solved my problem. Now the only issue left is that when
resizing the form, TabPage headers still flicker; but i guess i can
live with it.

Thanks once again!

Regards
Ankit!!
 
By overriding the CreateParams property for the Form, i was able to
get rid of the flickering completely.


protected override CreateParams CreateParams {
get {
CreateParams cp = base.CreateParams;
cp.ExStyle |= 0x02000000;
return cp;
}
}


Regards,
Ankit!!
 
protected override CreateParams CreateParams {
get {
CreateParams cp = base.CreateParams;
cp.ExStyle |= 0x02000000;
return cp;
}
}

Be aware that this Style Flag (WS_EX_COMPOSITED) is only available in WinXP
and Vista. It will have no effect in previous OS's.
 
Hi Ankit,

Thanks a bunch Mick...

Your hack solved my problem. Now the only issue left is that when
resizing the form, TabPage headers still flicker; but i guess i can
live with it.

The tabs in the TabControl you downloaded from my site shouldn't flicker,
but if the standard TabControl will do what you want, then it's best to use
that.
 
Back
Top