How to close one Usercontrol and open another via Panel

Asked

Viewed 182 times

1

I have userControlVicles inside a Panel, in this Usercontrol has a button to register a new vehicle, I want that when you click the button the panel closes or hide the current Ucontrol and show the new, I managed to show the registration, but I can’t make the old one go away..

private void metroButton1_Click(object sender, EventArgs e)
    {
        UserControlCadastroVehicle userControlCadastroVehicle = new UserControlCadastroVehicle();
        panel1.Controls.Add(userControlCadastroVehicle);
        panel1.Controls.Remove(this);
    }

I thought Remove(this) would close the Usercontrol I was, but it didn’t work, Hide() it goes away, but then add it all up, until the registration I opened. Fica assim

It looks like this when I click to register

1 answer

0

panel1.Controls.Clear();
        UserControlCadastroVehicle userControlCadastroVehicle = new UserControlCadastroVehicle();
        panel1.Controls.Add(userControlCadastroVehicle);

I got it, it was bad for the cloudy kkkk, I started playing with Forms now, but in case someone falls here looking for the answer, okay

Browser other questions tagged

You are not signed in. Login or sign up in order to post.