From: Jacko on

Hi

I have a UserControls with 20 buttons, how do i create a single delegate for
all these buttons for the click event, which will show in the hosted windows
form.

Pointer to source will be helpful

Regards
Jacko


From: Jacko on

Forgot to mention, the project is in VB.NET

"Jacko" <someone(a)somewhere.com> wrote in message
news:%23hAuFnBdKHA.5156(a)TK2MSFTNGP04.phx.gbl...
>
> Hi
>
> I have a UserControls with 20 buttons, how do i create a single delegate
> for all these buttons for the click event, which will show in the hosted
> windows form.
>
> Pointer to source will be helpful
>
> Regards
> Jacko
>
>


From: Family Tree Mike on


"Jacko" wrote:

>
> Forgot to mention, the project is in VB.NET
>
> "Jacko" <someone(a)somewhere.com> wrote in message
> news:%23hAuFnBdKHA.5156(a)TK2MSFTNGP04.phx.gbl...
> >
> > Hi
> >
> > I have a UserControls with 20 buttons, how do i create a single delegate
> > for all these buttons for the click event, which will show in the hosted
> > windows form.
> >
> > Pointer to source will be helpful
> >
> > Regards
> > Jacko
> >
> >
>
>
> .
>

Create a subroutine to handle all the buttons:

private sub ClickSub _
(ByVal sender as System.Object, ByVal e as System.EventArgs)
MessageBox.Show("Here...")
end sub



Then in the form constructor, you do the following for all buttons:

AddHandler Button1.Click, AddressOf ClickSub


I don't know what the fragment of your question "...which will show in the
hosted windows form" means.

Mike
From: OmegaSquared on
Hello, Jacko,

If I understand the question correctly...

You need to define a common click Event for your UserControl and raise this
event in the event handler(s) for the buttons. For example:

Public Class MBUserControl

Public Event ButtonClick(ByVal sender As System.Object, ByVal e As
System.EventArgs)

Private Sub Button_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) _
Handles Button1.Click, Button2.Click,
Button3.Click, Button4.Click
RaiseEvent ButtonClick(sender, e)
End Sub

End Class

And then when you add this UserControl to a Form, you can handle the
ButtonClick event. For example:

Public Class Form1

Private Sub MbUserControl1_ButtonClick(ByVal sender As Object, ByVal
e As System.EventArgs) _
Handles
MbUserControl1.ButtonClick
Dim cmdSender As Button = DirectCast(sender, Button)
MsgBox("Button """ & cmdSender.Name & """ was clicked.")
End Sub

End Class

Cheers,
Randy

From: Jacko on
Thanks

"OmegaSquared" <OmegaSquared(a)discussions.microsoft.com> wrote in message
news:0C55322A-EA6E-4F26-8E11-63171DBFF0D2(a)microsoft.com...
> Hello, Jacko,
>
> If I understand the question correctly...
>
> You need to define a common click Event for your UserControl and raise
> this
> event in the event handler(s) for the buttons. For example:
>
> Public Class MBUserControl
>
> Public Event ButtonClick(ByVal sender As System.Object, ByVal e As
> System.EventArgs)
>
> Private Sub Button_Click(ByVal sender As System.Object, ByVal e As
> System.EventArgs) _
> Handles Button1.Click, Button2.Click,
> Button3.Click, Button4.Click
> RaiseEvent ButtonClick(sender, e)
> End Sub
>
> End Class
>
> And then when you add this UserControl to a Form, you can handle the
> ButtonClick event. For example:
>
> Public Class Form1
>
> Private Sub MbUserControl1_ButtonClick(ByVal sender As Object,
> ByVal
> e As System.EventArgs) _
> Handles
> MbUserControl1.ButtonClick
> Dim cmdSender As Button = DirectCast(sender, Button)
> MsgBox("Button """ & cmdSender.Name & """ was clicked.")
> End Sub
>
> End Class
>
> Cheers,
> Randy
>