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
121 views
in Technique[技术] by (71.8m points)

c# - Communicating between forms

I would like to know how to communicate between forms using C#?

In Visual Basic it was easier since each form had it's own instance, with C# it's different.

In the Program Class I setup a public and static variable that hold my form:

public static FormProcess2 frmProcess2 = null;

Then in the Main method I create the form and show it up:

frmProcess2 = new FormProcess2();
frmProcess2.ShowDialog();

Now when that form loads, it load a background process that process XML files. And the method that process all the files are in another class name XMLParser. So in the BackgroundWorker doWork I load that method by:

XMLParser.Start();

Now the question is, how I can modify the frmProcess2 controls in the XMLParser class? I wanted it to show what's being updated by changing the label text as well as put some nice progress bar there.

But I can't access the Program.frmProcess2 controls, all I can access is it's defaults only...

See Question&Answers more detail:os

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

1 Reply

0 votes
by (71.8m points)

well you can use delegates to communication between windows forms. Check http://www.c-sharpcorner.com/uploadfile/mosessaur/winformsdelegates09042006094826am/winformsdelegates.aspx

For Delegates

EDIT

Check Delegates (C# Programming Guide)

http://msdn.microsoft.com/en-us/library/ms173171%28VS.80%29.aspx

Creating Custom Delegates and Events in C#

http://www.csharphelp.com/2007/02/creating-custom-delegates-and-events-in-c/

Introduction to Delegates and Events

http://www.csharp-station.com/Tutorials/lesson14.aspx


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

...