Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
490 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 Answer

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...