By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,041 Members | 1,046 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,041 IT Pros & Developers. It's quick & easy.

Pvt Sub X_Click(...) Handles btn1.Click, btn2.Click - multi contro

P: n/a
Hello,

If I have a sub that handles multiple controls - such as

Private Sub X_Click(ByVal sender As System.Object, ByVal e As EventArgs)
Handles btn1.Click, btn2.Click

If btn1.Click = true then messagebox.show "Btn1"
If btn2.Click = true then messagebox.Show "Btn2"

End Sub

How does Sub X_click know which button was clicked? How do I use sender or
e in this situation?

Thanks,
Rich
Nov 21 '05 #1
Share this Question
Share on Google+
7 Replies


P: n/a
Rich wrote:
Hello,

If I have a sub that handles multiple controls - such as

Private Sub X_Click(ByVal sender As System.Object, ByVal e As EventArgs)
Handles btn1.Click, btn2.Click

If btn1.Click = true then messagebox.show "Btn1"
If btn2.Click = true then messagebox.Show "Btn2"

End Sub

How does Sub X_click know which button was clicked? How do I use sender or
e in this situation?

Thanks,
Rich


one way:

Private Sub X_Click(ByVal sender As System.Object, ByVal e As EventArgs)
Handles btn1.Click, btn2.Click

select case directcast(sender, button).name
case btn1.name
messagebox.show "Btn1"
case btn2.name
messagebox.Show "Btn2"
end if
End Sub

There is a way doing it with "Is" I think, but not sure exactly.

chris
Nov 21 '05 #2

P: n/a
Rich,

Private Sub X_Click(ByVal sender As System.Object, ByVal e As EventArgs)
Handles btn1.Click, btn2.Click


Roughly typed
\\\\
Select case directcast(sender,button).name
case "btn1"
'do for btn1
case "btn2"
'do for btn2
End select
///

I hope this helps,

Cor
Nov 21 '05 #3

P: n/a
Chris,

Before you think it, I did not copy it from you. I had not seen your message
before I send it.

:-)

Cor
Nov 21 '05 #4

P: n/a
"Rich" <Ri**@discussions.microsoft.com> schrieb:
If I have a sub that handles multiple controls - such as

Private Sub X_Click(ByVal sender As System.Object, ByVal e As EventArgs)
Handles btn1.Click, btn2.Click

If btn1.Click = true then messagebox.show "Btn1"
If btn2.Click = true then messagebox.Show "Btn2"

End Sub

How does Sub X_click know which button was clicked? How do I use sender
or
e in this situation?

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

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

Nov 21 '05 #5

P: n/a
Herfried,

\\\
Dim SourceControl As Button = DirectCast(sender, Button)
Select Case True
Case SourceControl Is Me.Button1
...
Case SourceControl Is Me.Button2
...


You are to much active in the C# Entwickler newsgroup the last times in my
opinion.

:-)))

Cor
Nov 21 '05 #6

P: n/a
Cor,

"Cor Ligthert [MVP]" <no************@planet.nl> schrieb:
\\\
Dim SourceControl As Button = DirectCast(sender, Button)
Select Case True
Case SourceControl Is Me.Button1
...
Case SourceControl Is Me.Button2
...


You are to much active in the C# Entwickler newsgroup the last times in my
opinion.

:-)))


Mhm... Why? C#'s "crippled" 'switch' statement doesn't support this sort
of selection...

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

Nov 21 '05 #7

P: n/a
Thanks all for your replies. Everything works great!

Thanks again,
Rich

"Rich" wrote:
Hello,

If I have a sub that handles multiple controls - such as

Private Sub X_Click(ByVal sender As System.Object, ByVal e As EventArgs)
Handles btn1.Click, btn2.Click

If btn1.Click = true then messagebox.show "Btn1"
If btn2.Click = true then messagebox.Show "Btn2"

End Sub

How does Sub X_click know which button was clicked? How do I use sender or
e in this situation?

Thanks,
Rich

Nov 21 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.