Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
494 views
in Technique[技术] by (71.8m points)

.net - C# Calling a method from another Form

Hi I have 2 Form Form1 and Form2

Form1 have a table and there is my records and there is a Void for refresh the table in the Form1.

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)

thanks.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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);

Next on Form2 you can access Form1 like this:

(Form1)this.Parent.RefreshTable();

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...