Reputation: 72
I've two froms which need to communicate simultaneously. When certain element in FORM B is clicked, FORM A is shown and some operation is performed. But the foreach loop inside FORM B should work when i click some next button in FORM A after the first operation.
Upvotes: 1
Views: 829
Reputation: 2897
Another option is to create your own events in FormB and subscribe to them in FormA
here is a few examples:
http://msdn.microsoft.com/en-us/library/8627sbea(v=vs.71).aspx
http://ondotnet.com/pub/a/dotnet/2002/04/15/events.html
http://www.switchonthecode.com/tutorials/csharp-snippet-tutorial-custom-event-handlers
Also here is a greate sample about how to do this:
How can I make my own event in C#?
Note also,while what V4Vendetta offered would be the easy way to do this-this however is probably the better way to do this,and also a better practice.
Upvotes: 1
Reputation: 38210
Can you modify the constructor of your FormA
public FormA(Form F1)
{
InitializeComponent();
formB = frm as FormB;
}
Show the form from FormB as
FormA frmA = new FormA(this);
frmA.Show();
Now you have a reference of FormB
in FormA. Now expose the loop logic in a public method which could be accessed by this instance of FormB
Hope this helps.
Upvotes: 1