Controlling one form from another

jimctr

Well-known member
Joined
Dec 1, 2011
Messages
52
Programming Experience
Beginner
I have two forms: Form1 and Form2.

I have a button on Form1, but eventually move to form 2 where I end up in a looping structure that I may want to break out of. One way to break out of it would be to respond to the button click event on Form1. How do I access an event from Form1 from the vantage point of Form2.

I was thinking on Form2 I would declare

Private WithEvents frm1 as New Form1, and then be able to access the button click of Button1 on Form1 in that manner, but it doesn't appear to be the case; I don't pull up the button name from frm1 which is present on Form1.

Thanks
 
This alls sounds fairly ugly. If you have a loop being executed in Form2 then that will be tying up the UI thread, which means that Form1 will not respond to a Button click anyway. To make it work you would need to use some sort of multi-threading. If you provide a description of what you're trying to achieve, rather than how you're trying to achieve it, then we can advise on the best implementation. At a guess, I'd say that it is likely to involve a BackgroundWorker, which is what you'd normally use in a form where you wanted to be able able to cancel out of a running task.
 
Back
Top