Search code examples
c#winformsvisual-studio-2012tabcontrol.net-4.5

how can i stop form flickering when using tabControl.TabPages[0].Controls.Add()?


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.


Solution

  • 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