Click here to Skip to main content
15,886,137 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
I want the usercontrol window to close when the button on the usercontrol is clicked. How do I do this?


What I have tried:

I tried this.hide or this.dispose, but when I use them, the buttons in my form window are not visible.
Posted
Updated 25-May-21 1:58am
Comments
BillWoodruff 25-May-21 10:41am    
"but when I use them, the buttons in my form window are not visible."

to assist you, we need to understand your design: what are the buttons on the Form, and what is their relationship to the UserControl ?

1 solution

You could just set Visible to false:
C#
private void MyUserContolButton_Click(object sender, EventArgs e)
    {
    Visible = false;
    }
But I'd probably leave it to the parent control or form by providing a "CloseRequest" Event that the parent can handle. See here: Transferring information between two forms, Part 2: Child to Parent[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900