PC Review


Reply
Thread Tools Rate Thread

Button Array

 
 
Jacko
Guest
Posts: n/a
 
      3rd Dec 2009

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


 
Reply With Quote
 
 
 
 
Jacko
Guest
Posts: n/a
 
      3rd Dec 2009

Forgot to mention, the project is in VB.NET

"Jacko" <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
>
> 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
>
>



 
Reply With Quote
 
Family Tree Mike
Guest
Posts: n/a
 
      3rd Dec 2009


"Jacko" wrote:

>
> Forgot to mention, the project is in VB.NET
>
> "Jacko" <(E-Mail Removed)> wrote in message
> news:%(E-Mail Removed)...
> >
> > 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
 
Reply With Quote
 
OmegaSquared
Guest
Posts: n/a
 
      3rd Dec 2009
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

 
Reply With Quote
 
Jacko
Guest
Posts: n/a
 
      4th Dec 2009

Thanks Mike

I used the addhandler method and got it working

Regards
Jacko


"Family Tree Mike" <(E-Mail Removed)> wrote in
message news:6A247C90-B2FE-425A-8495-(E-Mail Removed)...
>
>
> "Jacko" wrote:
>
>>
>> Forgot to mention, the project is in VB.NET
>>
>> "Jacko" <(E-Mail Removed)> wrote in message
>> news:%(E-Mail Removed)...
>> >
>> > 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



 
Reply With Quote
 
Jacko
Guest
Posts: n/a
 
      4th Dec 2009
Thanks

"OmegaSquared" <(E-Mail Removed)> wrote in message
news:0C55322A-EA6E-4F26-8E11-(E-Mail Removed)...
> 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
>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How Do You Add Event Handler to 50 button array???? Armin Zingler Microsoft VB .NET 0 13th May 2008 11:36 PM
button array question Starbuck Microsoft VB .NET 3 10th Feb 2005 02:18 PM
Array of Button like in C# Picander Microsoft VC .NET 1 11th Jan 2005 01:01 PM
Button Array with faster painting Carl Gilbert Microsoft VB .NET 2 15th Nov 2004 07:16 PM
button array Tombatore Microsoft VB .NET 4 4th Nov 2004 08:40 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:31 PM.