本文介绍了C#调用从另一种形式的方法,的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
喜我有2个表Form 1和Form
HiI have 2 Form Form1 and Form2
Form1中有一个表,并有我的记录,并有一个虚空的刷新在Form1表。
Form1 have a table and there is my records and there is a Void for refresh the table in the Form1.
窗体2是我的插入表格我insertig数据sqlserver.I wantto,当后,我保存窗体2记录运行Form1中刷新无效。(当Form1的,Form2的打开)
Form2 is my insert form I am insertig data to sqlserver.I wantto that When after i save the record in Form2 to run Form1 Refresh void.(when Form1,Form2 opened)
感谢。
推荐答案
窗体2必须有一个参考到Form1的实例。你可以通过这个引用到窗体2单击插入按钮时:
Form2 will have to have a reference to the instance of Form1. You can pass this reference to Form2 when the insert button is clicked:
Form2 insertForm = new Form2();
//Form2.ShowDialog(Me); - Correction - 'Me' is for VB. in C# it's:
Form2.ShowDialog(this);
接下来Form 2上,您可以访问Form1中是这样的:
Next on Form2 you can access Form1 like this:
(Form1)this.Parent.RefreshTable();
这篇关于C#调用从另一种形式的方法,的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!