如何将控制权返回到启动表单

如何将控制权返回到启动表单

本文介绍了如何将控制权返回到启动表单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我有两种形式(Form1和Form2).
Form1包含DataGridView和添加"按钮.
运行表单时,第一个Form1将打开并保持原样,然后在我单击Add按钮时打开Form2.

我的问题是关闭Form2后,Form1应该保持原样并自行更新.

请提供示例或示例代码.

Hi all,

I''ve two forms (Form1 and Form2).
Form1 contains DataGridView and Add button.
While running the form, 1st Form1 will be open, retaining as it is, then Form2 will be opening as I clicked Add button.

my question is After closing Form2,Form1 should get stay as it is and updated itself.

Please reply with an example or sample code.

推荐答案


Form2 frm2 = new Form2(this);



在form2中,您可以创建一个像这样的构造函数:



In form2 you can create a constructor like this :

public static Form1 Frm1 = new Form1();

public Form2(Form1 form)
{
     Frm1 = form
}



现在,将form1的修改器设置为public后,您就可以访问它的任何控件.



now you can access any control of form1 after setting its modifier to public.


public Form2()
{
     InitializeComponent();
}



全局对象和重载的构造函数代码将是:



The global object and the overloaded constructor code will be :

public static Form1 Frm1 = new Form1();

public Form2(Form1 form)
{
     InitializeComponent();
     Frm1 = form;
}



现在,您可以在form1的修饰符中将datagridview设置为public.

然后在点击添加按钮事件中,您将插入以下代码以打开form2:



Now you can set your datagridview in form1 ''s modifier to public .

Then in the click add button event you will insert this code for opening form2 :

Form2 Frm2 =new Form2(this);
Frm2.show();



现在在form2代码中,您可以使用:
更新form1中的datagridview



now in the form2 code you can update your datagridview in form1 using :

Frm1.dataGridView1.Rows[...].Cells[...].Value = "<your desired="" data="">";
</your>



我希望这次很清楚,
祝你好运
:)



I Hope this time it is clear ,
Good luck
:)


这篇关于如何将控制权返回到启动表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-23 22:35