Click here to Skip to main content
15,888,454 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Hi all
In parent form I put the button property as enable false and how to enable the buttons from child form in C#.net (windows forms)?
Posted
Updated 18-Oct-10 19:47pm
v2

Pass a variable for parent form to child form, make the button variable public and set parent.button.Enabled = false;
 
Share this answer
 
Comments
Dalek Dave 19-Oct-10 4:38am    
Good Answer.
dmageiras 19-Oct-10 5:21am    
Thank you Dalek
Hi,

You can do that in following way

1. show the child window and while showing child, set the owner property of child form object to the parent form as shown following

private void btnShowChild_Click(object sender, EventArgs e)
{
            ChildForm ch = new ChildForm();
            ch.Owner = this;
            ch.ShowDialog();
}


2. In childForm, get the reference to Parent form (which was earlier set as owner of the childForm ) as shown here

ParentForm p = (ParentForm)this.Owner;


3. Once you have the reference to parent form object instance from child form, you get any control(say a button named "button2" in parentForm) using following way

private void btnDisableParentButton_Click(object sender, EventArgs e)
{

            ParentForm p = (ParentForm)this.Owner;
            Control[] c = p.Controls.Find("button2", true);
            Button b = (Button)c[0];
            b.Enabled = false;
}


NB: I am disabling a button named "button2" in Parent form from a child window.

Please let me know if that was usefull to you.

Thanks
Arindam D Tewary
 
Share this answer
 
Comments
Dalek Dave 19-Oct-10 4:38am    
Good Call.
Arindam Tewary 19-Oct-10 4:48am    
Thanks Dalek for encouraging words :)
J.Karthick 24-May-11 9:52am    
yaa....its works fine...Thanks a loooooot Arindam D Tewary
Asavani Anil 22-Aug-19 1:21am    
thanks it work for me and save lot of my time.

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