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 7 1730
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(send er, 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
Rich, Private Sub X_Click(ByVal sender As System.Object, ByVal e As EventArgs) Handles btn1.Click, btn2.Click
Roughly typed
\\\\
Select case directcast(send er,button).name
case "btn1"
'do for btn1
case "btn2"
'do for btn2
End select
///
I hope this helps,
Cor
Chris,
Before you think it, I did not copy it from you. I had not seen your message
before I send it.
:-)
Cor
"Rich" <Ri**@discussio ns.microsoft.co m> 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(send er, 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/>
Herfried, \\\ Dim SourceControl As Button = DirectCast(send er, 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
Cor,
"Cor Ligthert [MVP]" <no************ @planet.nl> schrieb: \\\ Dim SourceControl As Button = DirectCast(send er, 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/>
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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Neven Klofutar |
last post by:
Hi,
I recently read an article on MSDN about viewstate and postback.
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnaspp/html/viewstate.asp
The author states the following:
"It is a common misconception among developers that view state is somehow
responsible for having TextBoxes, CheckBoxes, DropDownLists, and other...
|
by: Alex |
last post by:
Hi Everyone,
I'm working through the Beginning Visual Basic 2005 book, but I have a
question that though might be obvious, I'm not seeing an explanation.
THe first example in the book is creating a simple form with two
buttons and a text box, but for example on the OK button, here's waht
is in the .vb file for this object:
Private Sub...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
| |
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...
| | |