Alex Gordon
Alex Gordon

Reputation: 60871

c# how to mimic a button press from a different form

i am creating a replica of my current form:

    Form form2 = new Form1();
    form2.Show();

i need to be able to run events on form2 like the button_click and fill out some text in a textbox. how do i do this?

Upvotes: 1

Views: 208

Answers (2)

Donnie
Donnie

Reputation: 46943

To run event handlers from another class make them public, default access modifier for class members in c# is private. note that this will very rapidly lead to highly coupled spaghetti code ... you should really refactor so that you don't need to call event handlers between forms like this, it's a bad habit.

Upvotes: 1

Neowizard
Neowizard

Reputation: 3027

Best way to edit the controls on a form is to create a method that exposes this feature (like an EditTextBox1(string) kind of method). In general, when you want to manipulate a form from code (except for the form's code) and not the gui, it's wise to create a method for this (in the form class).

Regarding running events, it's unclear what you mean

Upvotes: 1

Related Questions