Click here to Skip to main content
16,018,092 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
private void btnSignUpOpt_Click(object sender, EventArgs e)
{
    Members aMember = new Members();
    aMember.Show();
    (sender as Button).Enabled = false;
            
}


this is how i disable it, but i cant find a way of enabling it after i close the form aMember.

What I have tried:

I tried:
C#
btnSignUp.Enable = true;

but that would make the button be enabled even if the form is already open
Posted
Updated 6-Sep-18 10:27am
v2

1 solution

There are many different ways of doing what you want:
1. open the form modally, then the code in the button event will pause until you close the aMember form;
2. enable the btnSignUpOpt from the aMember close event
3. pass an Action to the aMember form before showing, then call the action from aMember before closing where the Action enables the button
4. listen to the closing event in the host form before showing the aMember form and enable the btnSignUpOpt when the event is captured
5. and so on...
 
Share this answer
 
Comments
Member 13975729 7-Sep-18 9:33am    
I tried the event to close form, but it was still throwing exceptions.
And i was not able to enable the button from the child form. I tried to create and instance of the parent form to call the button, but was not possible.
Richard Deeming 7-Sep-18 10:13am    
private void btnSignUpOpt_Click(object sender, EventArgs e)
{
    Button btn = (Button)sender;
    Members aMember = new Members();
    aMember.Closed += delegate { btn.Enabled = true; };
    aMember.Show();
    btn.Enabled = false;     
}


If you're getting an exception, then you need to provide the full details of the exception.
Graeme_Grant 7-Sep-18 17:59pm    
That is another way ... ;)

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