J
JohnR
In it's simplest form, assume that I have created a usercontrol,
WSToolBarButton that contains a button. I would like to eventually create
copies of WSToolBarButton dynamically at run time based on some
initialization information obtained elsewhere. Basically, I'm going to
create my own dynamic toolbar where the toolbarbuttons can change. I'm not
using the VB toolbar because of limitations in changing things like
backcolor (I can't get it to change, but that's another story).
For testing purposes I simply dragged a copy of WSToolBarButton from the
usercontrol toolbox to the form. I set up a sub to handle the click event
of the WSToolBarButton. This sub displays a messagebox "usercontrol click
fired". The problem is that the click event is fired only when I click
somewhere in WSToolBarButton but NOT in the button that is part of
WSToolBarButton. If I click on the button nothing happens.
So, I went into the code for WSToolBarButton and set up a click event for
the button which display a msgbox "button click fired". Running the
program if I click the button I get "button click fired" and that's all. I
don't get "usercontrol click fired". However, if I click somewhere in
WSToolBarButton but not in the button I do get "usercontrol click fired".
My question is how exactly can I set up WSToolBarButton so that if a user
clicks anywhere within the control I will execute the click event of the
MYUSERCONTROL (the one that says "usercontrol click fired") . I guess I
somehow have to fire the WSToolBarButton click event from within the button
click event but I just don't know how to set it up. I've played with
RAISEEVENT but had no luck at all. I tried calling the
WSToolBarButton_Click sub directly from the Button click event sub, but it
doesn't bubble up to the click event on the main form.
I'm totally out of ideas here... Can anybody explain what I would need to
do to get this to work? I've attached the code snippets at the end of the
msg.
Thanks,
John
********************* this code is in my usercontrol
****************************
Public Class WSToolbarButton
Inherits System.Windows.Forms.UserControl
#Region " Windows Form Designer generated code " <snip>
#End Region
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
MsgBox("button click fired")
WSToolbarButton_Click(sender, e)
End Sub
Private Sub WSToolbarButton_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.Click
MsgBox("wstoolbarbutton click raised")
'at this point the click event for this usercontrol on the main form
is fired ONLY IF this routine was caused
'by clicking the WSToolBarButton somewhere other than the button. If
this routine was called from the
'button1_click routine the click event for this usercontrol on the
main form WILL NOT execute.
End Sub
End Class
****************** this code is from my main form
***************************
Private Sub WsToolbarButton1_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles WsToolbarButton1.Click
MsgBox("usercontrol click fired")
End Sub
WSToolBarButton that contains a button. I would like to eventually create
copies of WSToolBarButton dynamically at run time based on some
initialization information obtained elsewhere. Basically, I'm going to
create my own dynamic toolbar where the toolbarbuttons can change. I'm not
using the VB toolbar because of limitations in changing things like
backcolor (I can't get it to change, but that's another story).
For testing purposes I simply dragged a copy of WSToolBarButton from the
usercontrol toolbox to the form. I set up a sub to handle the click event
of the WSToolBarButton. This sub displays a messagebox "usercontrol click
fired". The problem is that the click event is fired only when I click
somewhere in WSToolBarButton but NOT in the button that is part of
WSToolBarButton. If I click on the button nothing happens.
So, I went into the code for WSToolBarButton and set up a click event for
the button which display a msgbox "button click fired". Running the
program if I click the button I get "button click fired" and that's all. I
don't get "usercontrol click fired". However, if I click somewhere in
WSToolBarButton but not in the button I do get "usercontrol click fired".
My question is how exactly can I set up WSToolBarButton so that if a user
clicks anywhere within the control I will execute the click event of the
MYUSERCONTROL (the one that says "usercontrol click fired") . I guess I
somehow have to fire the WSToolBarButton click event from within the button
click event but I just don't know how to set it up. I've played with
RAISEEVENT but had no luck at all. I tried calling the
WSToolBarButton_Click sub directly from the Button click event sub, but it
doesn't bubble up to the click event on the main form.
I'm totally out of ideas here... Can anybody explain what I would need to
do to get this to work? I've attached the code snippets at the end of the
msg.
Thanks,
John
********************* this code is in my usercontrol
****************************
Public Class WSToolbarButton
Inherits System.Windows.Forms.UserControl
#Region " Windows Form Designer generated code " <snip>
#End Region
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
MsgBox("button click fired")
WSToolbarButton_Click(sender, e)
End Sub
Private Sub WSToolbarButton_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.Click
MsgBox("wstoolbarbutton click raised")
'at this point the click event for this usercontrol on the main form
is fired ONLY IF this routine was caused
'by clicking the WSToolBarButton somewhere other than the button. If
this routine was called from the
'button1_click routine the click event for this usercontrol on the
main form WILL NOT execute.
End Sub
End Class
****************** this code is from my main form
***************************
Private Sub WsToolbarButton1_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles WsToolbarButton1.Click
MsgBox("usercontrol click fired")
End Sub