Hi,
how do you control USERCONTROL button1_click event from form's button2_click event?
button 1 = hidden button on usercontrol1
button2 = visible button on form1
form1.button2 should click usercontrol.button1
regards, and thanks in advance :)
Printable View
Hi,
how do you control USERCONTROL button1_click event from form's button2_click event?
button 1 = hidden button on usercontrol1
button2 = visible button on form1
form1.button2 should click usercontrol.button1
regards, and thanks in advance :)
i don't really get what you mean but this is what im thought you asked for
Code:usercontrol.Button1.PerformClick()
Hi thanks for the reply but that does not work.
it gives error, "Reference to a non-shared member requires an object reference"
:)
all i want is (buttonA on form1) to click (buttonB on Usercontrol1) the same time.
Assume your UserControl1 has a Button on it Named Button1. Then assume that you have a silly MsgBox placed in the Button1_Click Event handler, as follows:
THEN Assume you have Form1, onto which you have placed an instance of UserControl1 using the designer. Also assume that you have placed Button2on Form1 in the designer, and placed the following in the event handling code for Button2:Code:Public Class UserControl1
Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
MsgBox("UserControl1 Button CLicked")
End Sub
End Class
When you click Button2 on Form1, it fires the Button2_CLick Event Handler. Within that method, the Me.UserControl1.Button1.Click Statement at once references the local instance of UserControl1, and calls the PerformCLick method. This fires the UserCOntrol1 Button1_CLick event handler code, which pops up the message box.Code:
Public Class Form1
Private Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button2.Click
Me.UserControl11.Button1.PerformClick()
End Sub
End Class
If you are getting that "non-shared member" business still, then you might need to explain to us how you have out your form together. It SOUNDS like somewhere you are not referencing an instance of UserControl1.
Did you add the usercontrol in the designer, or did you add it programmatically?
This should work. If it does not, then could you please post your current code for Both UserControl and Form?
Thanks RunsWithScissors :)
works perfectly. SOLVED