问题描述
大家好
在父窗体中,我将button属性设置为enable false,以及如何从C#.net的子窗体(Windows窗体)中启用按钮?
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)?
推荐答案
private void btnShowChild_Click(object sender, EventArgs e)
{
ChildForm ch = new ChildForm();
ch.Owner = this;
ch.ShowDialog();
}
2.在childForm中,获取对Parent表单的引用(先前已将其设置为childForm的所有者),如下所示:
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.一旦从子表单中引用了父表单对象实例,就可以使用以下方式获得任何控件(例如parentForm中名为"button2"的按钮)
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;
}
注意:我正在从子窗口中禁用父窗体中名为"button2"的按钮.
请让我知道这对您是否有用.
谢谢
Arindam D Tewary
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
这篇关于如何启用C#.net中子窗体中父窗体中的按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!