Click here to Skip to main content
15,892,768 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello.
Im using windows forms c#. im trying to make form2 button click from form1
how can done that help please
For example:
private void dataGridView1_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            AddNew an = new AddNew();
an.btnOk.Click == an.txtProductName.Text = "Fine";

This does not work what is your advice?
THanks :)
Posted

Provide a public accessor on the form you want the click operation performed, then call this from the other form.

e.g.
Form 1 (The one with the button)
C#
Public void doClick()
{
   buttonXYZ.performClick();
}


Form 2
C#
form1.doClick();


You obviously need to have an object reference already active within form 2
 
Share this answer
 
v2
Comments
#realJSOP 26-Oct-10 12:19pm    
Proposed as correct answer.
lester555 26-Oct-10 12:31pm    
thanks . its work
Dalek Dave 26-Oct-10 18:18pm    
Good answer.
Instead of simulating a button click, it would be much better to perform the action that the button's click handler would otherwise have done.
 
Share this answer
 
First you will need a reference to the button of form2 in form1.
Then you can simply do _myButton_Event(null,null).
 
Share this answer
 
Comments
Dalek Dave 26-Oct-10 18:18pm    
Good Call.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900