Reputation: 17477
I need to call tabControl1_SelectedIndexChanged
from Form1
in Form2
I have no idea how do this.
Upvotes: 1
Views: 175
Reputation: 48179
As Jon mentioned, you shouldn't make public... Here are some other samples that I've posted previously that explicitly walk through the creation of two forms and how to pass back-and-forth. Check these out
Upvotes: 2
Reputation: 888203
You should make a public method in the first form that performs the logic you need.
Then, pass an instance of the first form to the second form and call the method on that instance.
Upvotes: 3
Reputation: 1503769
In general, you don't call events from other classes. The idea is that events expose subscribe/unsubscribe behaviour. The implementation can choose to also expose a method which raises the event, but it doesn't have to - and if the control you're using doesn't expose such a method for the SelectedIndexChanged
event, you can't force it to.
It's not clear what you're trying to achieve, but you may be able to programmatically select the appropriate tab instead - I'd expect that to raise the appropriate event. Rather than expose the tab control directly from Form1
to Form2
(which I hope are only placeholder names - give your forms meaningful names :) it would be cleaner to expose a method in Form1
to perform the selection of the appropriate tab. That's a more meaningful operation to perform on Form1
- it doesn't rely as heavily on the implementation details. On the other hand, you may be able to create an even cleaner design using MVP patterns (or whatever suits you best).
Upvotes: 6