1

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.

Muhammad Ali
  • 72
  • 10

2 Answers2

1

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.

V4Vendetta
  • 37,194
  • 9
  • 78
  • 82
1

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.

Community
  • 1
  • 1
Eli Braginskiy
  • 2,867
  • 5
  • 31
  • 46