Reputation: 9416
am using below code to add a Form to a tabControls tabPage
private void btnStudents_Click(object sender, EventArgs e)
{
foreach (Form c in tabStudents.TabPages[0].Controls)
{
tabStudents.TabPages[0].Controls.Remove(c);
c.Dispose();
}
//load form
StudentsMasterForm f = new StudentsMasterForm
{
TopLevel = false,
FormBorderStyle = FormBorderStyle.None,
Dock = DockStyle.Fill
};
tabStudents.TabPages[0].Controls.Add(f);
f.Show();
}
the problem however is, there is too much form flickering when the button is clicked (i.e when the form is loaded). I have tried using tabCustomersAndOrders.TabPages[0].SuspendLayout();
and tabCustomersAndOrders.TabPages[0].ResumeLayout();
` but the flickering isn't going away.
I want to transition from one form to another to be as smooth as possible.
Upvotes: 0
Views: 12162
Reputation: 31
Just paste this in your main GUI:
protected override CreateParams CreateParams
{
get
{
CreateParams cp = base.CreateParams;
cp.ExStyle |= 0x02000000; // Turn on WS_EX_COMPOSITED
return cp;
}
}
this should solve your problem. At least from many things that I searched over the web, this one helped.
Upvotes: 1
Reputation: 9416
For the purpuse of marking this question as answered, here i post a link to another stackoverflow question that has a solution to my question.
Here is the link how to fix the flickering in user controls
Upvotes: 0
Reputation: 1596
Enabling double-buffering on the TabControl might help. With double-buffering, the control graphics all get rendered into memory, and then displayed only when all control rendering is complete.
This will mean a visible delay until completion, but should remove the flickering effect of multiple controls rendering.
The following will enable double-buffering:
myTabControl.SetStyle(ControlStyles.DoubleBuffer |
ControlStyles.UserPaint |
ControlStyles.AllPaintingInWmPaint,
true);
The other alternative (the one I'd recommend) is to look at the problem from a different angle. Is there any way you can alter the UI design so that this kind of form population is pre-cached, or occurs before rendering to screen?
Upvotes: 2