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

Detect button click-event in groupbox

P: n/a
Hello everyone,

I've a form with a groupbox witch contain 4 buttons. I searching for a
solutions to detect when I click on one of the buttons returning a reference
to the button thas has been pressed.

Thanks in advance,

Benny
Nov 21 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
Hi Ben,

You mean something as in the click event of the button
Button1.text = "I have been clicked"

You can set for every button whatever you want or are you maybe talking bout
the toolbar?

Cor

"BenCoo" <be****@NOSPAMtelenet.be>
Hello everyone,

I've a form with a groupbox witch contain 4 buttons. I searching for a
solutions to detect when I click on one of the buttons returning a
reference to the button thas has been pressed.

Thanks in advance,

Benny

Nov 21 '05 #2

P: n/a
"BenCoo" <be****@NOSPAMtelenet.be> schrieb:
I've a form with a groupbox witch contain 4 buttons. I searching for a
solutions to detect when I click on one of the buttons returning a
reference to the button thas has been pressed.


Add a handler to the button's 'Click' event (this can be done by
doubleclicking the button in the Windows Forms designer). You can cast the
parameter 'sender' to 'Button' if you need a reference to the button that
raised the event, for example.

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

Nov 21 '05 #3

P: n/a
The meaining of the buttons in the groupbox is to calculate a sum. Each
button has a text "10", "20", "30", and so on...In stead of use each buttons
click-event to calculate : sum += 10, sum+= 20, I want to use something
like this:

Select Case ButtonPressed
case "Button10"
sum += 10
case "Button20"
sum += 20
case "Button30"
sum += 30
End Select

"BenCoo" <be****@NOSPAMtelenet.be> schreef in bericht
news:Im*******************@phobos.telenet-ops.be...
Hello everyone,

I've a form with a groupbox witch contain 4 buttons. I searching for a
solutions to detect when I click on one of the buttons returning a
reference to the button thas has been pressed.

Thanks in advance,

Benny

Nov 21 '05 #4

P: n/a

"BenCoo" <be****@NOSPAMtelenet.be> wrote
The meaining of the buttons in the groupbox is to calculate a sum. Each
button has a text "10", "20", "30", and so on...In stead of use each buttons
click-event to calculate : sum += 10, sum+= 20, I want to use something
like this:

Select Case ButtonPressed
case "Button10"
sum += 10
case "Button20"
sum += 20
case "Button30"
sum += 30
End Select

You can declare one routine to handle multiple events, such as:
Private Sub ButtonClicks(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles Button10.Click, Button20.Click, Button30.Click
If sender Is Button10 Then
sum += 10
ElseIf sender Is Button20 Then
sum += 20
ElseIf sender Is Button30 Then
sum += 30
End If
End Sub
HTH
LFS
Nov 21 '05 #5

P: n/a
Thanks Larry !! You've put me on the right track !!

I use you're solution, but in the Tag-propertie of each button I place the
value (Button10.Tag = 10, Button20.Tag = 20, and so on) and then I've only
to add the next code to the eventhandler: sum += sender.Tag

Life can be simple ;-)

Again, Thanks a lot
Benny

"Larry Serflaten" <se*******@usinternet.com> schreef in bericht
news:ef**************@TK2MSFTNGP10.phx.gbl...

"BenCoo" <be****@NOSPAMtelenet.be> wrote
The meaining of the buttons in the groupbox is to calculate a sum. Each
button has a text "10", "20", "30", and so on...In stead of use each
buttons
click-event to calculate : sum += 10, sum+= 20, I want to use something
like this:

Select Case ButtonPressed
case "Button10"
sum += 10
case "Button20"
sum += 20
case "Button30"
sum += 30
End Select

You can declare one routine to handle multiple events, such as:
Private Sub ButtonClicks(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles Button10.Click, Button20.Click,
Button30.Click
If sender Is Button10 Then
sum += 10
ElseIf sender Is Button20 Then
sum += 20
ElseIf sender Is Button30 Then
sum += 30
End If
End Sub
HTH
LFS

Nov 21 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.