[英]Reload a Form through another Form by Button click
I have two forms: Form1
and Form2
. 我有两种形式:
Form1
和Form2
。
On Form1
I have a button. 在
Form1
我有一个按钮。 And through that button I want to reload the Form2
. 通过该按钮,我想重新加载
Form2
。 On From2_Load
event I've some code which will update the picture on every load. 在
From2_Load
事件中,我有一些代码将在每次加载时更新图片。
But I'm unable to accomplish the task. 但是我无法完成任务。 I'm using this code to reload, but failed to do that.
我正在使用此代码重新加载,但未能完成。
This is my 'On button click' event code: 这是我的“单击按钮”事件代码:
Form2 frm = new from2();
frm.refresh();
I don't want to hide the Form2
. 我不想隐藏
Form2
。 I just want to close it and reopen it on each click. 我只想关闭它,然后在每次单击时重新打开它。
As you said you have some code in your Form_Load
event... Why not do this? 如您所说,您的
Form_Load
事件中有一些代码...为什么不这样做?
private void form2_Load()
{
Mycodes()///call it if required
}
public void MyCodes()
{
// Move codes from load event to here
}
// Now from Form1
public class form1
{
Form2 frm = new Form2() ///make sure u declare it in class level
private void Bttn_Click()
{
frm.MyCodes();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.