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

Categories

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

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

1 Answer

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...