InvokeOnClick Method in VS2005

R

RickSean

I have a main form frmMain containing a button button1

I have another form frmNew containing a textbox txtBox1 and a button button2.

I have the following code behind the button button2 in frmNew:
Messagebox.Show(txtBox2.Text.tostring());

I have the following code behind the button button1 in frmMain:
frmMain frm = new frmNew();
Button btn = frm.button2;
this.InvokeOnClick(btn, EventArgs.Empty);

When application is launched; both forms a re displayed on the screen. I
entered a "My Text Message" in the frmNew's textbox txtBox1 and then went to
frmMain and clicked the button button1 which invoked the click event on
frmNext to display the message box

The code above displays the messagebox but it is blank; it should display
"John Doe" but doesn't. Please help!!!
 
P

Pavel Minaev

RickSean said:
I have a main form frmMain containing a button button1

I have another form frmNew containing a textbox txtBox1 and a button button2.

I have the following code behind the button button2 in frmNew:
Messagebox.Show(txtBox2.Text.tostring());

I have the following code behind the button button1 in frmMain:
frmMain frm = new frmNew();
Button btn = frm.button2;
this.InvokeOnClick(btn, EventArgs.Empty);

When application is launched; both forms a re displayed on the screen. I
entered a "My Text Message" in the frmNew's textbox txtBox1 and then went to
frmMain and clicked the button button1 which invoked the click event on
frmNext to display the message box

The code above displays the messagebox but it is blank; it should display
"John Doe" but doesn't. Please help!!!

The documentation on InvokeOnClick seems pretty scarce, but it's
rather telling that it's not a static method. I would not be surprised
if you'd have to call it either on the control itself (though then
it's not clear why you have to pass "toInvoke" argument, which would
be the same thing), on its container, or on the form which contains
it.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top