[英]How to affect child form from parent form in mdi c#
My problem is that I have created child's object and show child first time. 我的问题是我已经创建了孩子的对象并且第一次显示孩子。 but when second time I just want to change value of child's label from parent but don't want to show another form.
但是第二次我只想从父母那里改变孩子的标签价值,但又不想表现出另一种形式。 Here is my code.
这是我的代码。
First time 第一次
ChildForm ObjChild = new ChildForm("Hi");
ObjChild.Show();
On second time I just want to set Bye in place of Hi. 第二次,我只想设置Bye代替Hi。
ChildForm ObjChild = new ChildForm("H!");
ObjChild.BringToFront();
Because child form is already opened. 因为子表单已经打开。 This is my child Form
这是我的孩子表格
public Form1(string p_Param)
{
InitializeComponent();
Label1.Text = p_Param;
}
Constructors call one time when object created. 构造函数在创建对象时调用一次。 You must implement a new public void or function rather than a constructor to do that.
您必须实现一个新的公共void或函数而不是构造函数来执行此操作。
public void ChangeLabelText(string txt)
{
Label1.Text=txt;
}
EDIT: 编辑:
In your parent form; 在您的父表格中; Out of functions;
没有功能;
chilFrm ChildForm;
Inside any function; 在任何功能内;
if (chilFrm == null)
{
chilFrm = new ChildForm();
chilFrm.TopLevel = false;
chilFrm.Parent = this;
chilFrm.StartUpProsecc("Created New");
chilFrm.Show();
}
else
{
chilFrm.StartUpProsecc("Showed the existing.");
chilFrm.BringToFront();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.