ameer
ameer

Reputation: 1

how to click on usercontrol to open anoter usercontrol?

im using visual c# 2008,i have tried to open usercontrol2 from usercontrol1. using event handling yet still unable to load the usercontrol1, but able to close the usercontrol1.

please help me..

Upvotes: 0

Views: 83

Answers (1)

Mark Hall
Mark Hall

Reputation: 54562

Give this a Try

void UserControl1_Click(object sender, EventArgs e)
    {
        UserControl2 u2 = new UserControl2();
        this.Parent.Controls.Add(u2); // if you want to add to parent
        //this.Controls.Add(u2); // if you want to add to the first UserControl
        u2.BringToFront();
        this.Visible = false;
        u2.Visible = true;
    }

I think your problem is that you did not assign usercontrol2 to a parents control collection.

Upvotes: 1

Related Questions