I have added handlers handlers to direct all buttons to one method like
this;

'Add handlers for buttons
AddHandler btnManageJobs.Click, AddressOf Button_Click
AddHandler btnSeqOfOper.Click, AddressOf Button_Click
AddHandler btnViewer.Click, AddressOf Button_Click
AddHandler btnScfmCalculationTool.Click, AddressOf Button_Click
AddHandler btnAdminSetup.Click, AddressOf Button_Click

How do I determine which button was clicked? I think I use "sender" but
do not know how. Can someone help me?

Thank you,
dbuchanan

Re: How do I determine which button was clicked by Tim

Tim
Sat Nov 12 10:07:57 CST 2005

If you need to access properties specific to the Button class then you can
cast the "sender" to the Button type using DirectCast.
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vblr7/html/vakeydirectcast.asp

To compare the "sender" to the buttons to see which Button was clicked you
can do something similar to the following code.

Private Sub Button_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs)
If (sender Is Button1) Then
' Handle Button1.Click
ElseIf (sender Is Button2) Then
' Handle Button2.Click
ElseIf (sender Is Button3) Then
' Handle Button3.Click
End If
End Sub

--
Tim Wilson
.NET Compact Framework MVP

"dbuchanan" <dbuchanan52@hotmail.com> wrote in message
news:1131810063.022402.100780@g44g2000cwa.googlegroups.com...
> I have added handlers handlers to direct all buttons to one method like
> this;
>
> 'Add handlers for buttons
> AddHandler btnManageJobs.Click, AddressOf Button_Click
> AddHandler btnSeqOfOper.Click, AddressOf Button_Click
> AddHandler btnViewer.Click, AddressOf Button_Click
> AddHandler btnScfmCalculationTool.Click, AddressOf Button_Click
> AddHandler btnAdminSetup.Click, AddressOf Button_Click
>
> How do I determine which button was clicked? I think I use "sender" but
> do not know how. Can someone help me?
>
> Thank you,
> dbuchanan
>



Re: How do I determine which button was clicked by Herfried

Herfried
Sat Nov 12 10:15:45 CST 2005

"dbuchanan" <dbuchanan52@hotmail.com> schrieb:
>I have added handlers handlers to direct all buttons to one method like
> this;
>
> 'Add handlers for buttons
> AddHandler btnManageJobs.Click, AddressOf Button_Click
> AddHandler btnSeqOfOper.Click, AddressOf Button_Click
> AddHandler btnViewer.Click, AddressOf Button_Click
> AddHandler btnScfmCalculationTool.Click, AddressOf Button_Click
> AddHandler btnAdminSetup.Click, AddressOf Button_Click
>
> How do I determine which button was clicked? I think I use "sender" but
> do not know how. Can someone help me?


\\\
Dim SourceControl As Button = DirectCast(sender, Button)
Select Case True
Case SourceControl Is btnManageJobs
...
Case...
...
End Select
///

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Re: How do I determine which button was clicked by Vagabond

Vagabond
Sat Nov 12 10:19:00 CST 2005

"dbuchanan" <dbuchanan52@hotmail.com> wrote in message
news:1131810063.022402.100780@g44g2000cwa.googlegroups.com...
>I have added handlers handlers to direct all buttons to one method like
> this;
>
> 'Add handlers for buttons
> AddHandler btnManageJobs.Click, AddressOf Button_Click
> AddHandler btnSeqOfOper.Click, AddressOf Button_Click
> AddHandler btnViewer.Click, AddressOf Button_Click
> AddHandler btnScfmCalculationTool.Click, AddressOf Button_Click
> AddHandler btnAdminSetup.Click, AddressOf Button_Click
>
> How do I determine which button was clicked? I think I use "sender" but
> do not know how. Can someone help me?
>
> Thank you,
> dbuchanan

In the click event handler...

name = CType(sender, Button).Name
Select Case name
Case "btnManageJobs"
'ManageBlah()
Case "btnSeqOfOper"
'GetSeq
Case "btnViewer"
'GetViewer
Case "btnScfmCalculationTool"
'GetTool
Case Else
'handle it
End Select

A better way might be to use a module-level hashtable with button names and
indexes.

Carl



Re: How do I determine which button was clicked by dbuchanan

dbuchanan
Sat Nov 12 13:39:53 CST 2005

Carl,

I've never used a hashtable. Do you have an example you could share.

Thank you,
dbuchanan


Re: How do I determine which button was clicked by JellevanderBeek

JellevanderBeek
Mon Nov 14 05:48:02 CST 2005

I would prefer not to check on the control's name property, since a change
from the control's name will result in a breaking change that will not be
easily detected.

Tim's solution is less error-prone.

"Vagabond Software" wrote:

> "dbuchanan" <dbuchanan52@hotmail.com> wrote in message
> news:1131810063.022402.100780@g44g2000cwa.googlegroups.com...
> >I have added handlers handlers to direct all buttons to one method like
> > this;
> >
> > 'Add handlers for buttons
> > AddHandler btnManageJobs.Click, AddressOf Button_Click
> > AddHandler btnSeqOfOper.Click, AddressOf Button_Click
> > AddHandler btnViewer.Click, AddressOf Button_Click
> > AddHandler btnScfmCalculationTool.Click, AddressOf Button_Click
> > AddHandler btnAdminSetup.Click, AddressOf Button_Click
> >
> > How do I determine which button was clicked? I think I use "sender" but
> > do not know how. Can someone help me?
> >
> > Thank you,
> > dbuchanan
>
> In the click event handler...
>
> name = CType(sender, Button).Name
> Select Case name
> Case "btnManageJobs"
> 'ManageBlah()
> Case "btnSeqOfOper"
> 'GetSeq
> Case "btnViewer"
> 'GetViewer
> Case "btnScfmCalculationTool"
> 'GetTool
> Case Else
> 'handle it
> End Select
>
> A better way might be to use a module-level hashtable with button names and
> indexes.
>
> Carl
>
>
>

Re: How do I determine which button was clicked by dbuchanan

dbuchanan
Tue Nov 15 08:28:15 CST 2005

Hi Jelle,

How is Tim not using the controls name property? How is Button1,
Button2.... not the button's name? It looks like it to me.


Thank you,
dbuchanan


Re: How do I determine which button was clicked by Tim

Tim
Tue Nov 15 09:56:45 CST 2005

If it was in quotes it would be. I am comparing references, not names. And I
like Herfried's way the best since it seems cleaner than a whole bunch of
if...elses. I'm not a VB guy so I wasn't sure if you could compare
references through a Select statement.

--
Tim Wilson
.NET Compact Framework MVP

"dbuchanan" <dbuchanan52@hotmail.com> wrote in message
news:1132064895.190754.161500@z14g2000cwz.googlegroups.com...
> Hi Jelle,
>
> How is Tim not using the controls name property? How is Button1,
> Button2.... not the button's name? It looks like it to me.
>
>
> Thank you,
> dbuchanan
>



Re: How do I determine which button was clicked by dbuchanan

dbuchanan
Tue Nov 15 11:09:46 CST 2005

Hi Tim, Jelle, others

Thanks for the input I understand what you mean by references - if the
button name changes the code is broken, but the compiler will indicate
where the break is the Task List.

Herfried's code is the one I chose for the same reasons Tim stated.


Thanks,
dbuchanan