|
-
Jun 24th, 2003, 02:41 AM
#1
Thread Starter
Junior Member
How to capture Button Index in .NET
Dear All,
In VB6 we can simply find out the command button index if we have series of buttons on form.
Example VB6 Code:-
Sub Command1_Click(Index as Integer)
' msgbox "You are pressed Button number :" & index
End Sub
How do we do it VB .NET ? so that we know what button we are pressed !
my .NET sample code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click, Button2.Click, Button3.Click
? What is the command to capture the button index
End Sub
TIA
regards
Jas
-
Jun 24th, 2003, 03:39 AM
#2
PowerPoster
It doesn't work that way in .Net, but to answer your question, the sender object that is passed in as an argument contains which button was clicked. Try something like this:
'Might be CommandButton, I am doing this from memory.
Dim myButton As Button
myButton = CType(sender, Button)
MessageBox.Show(myButton.Name.ToString())
Remember, you have to cut me some slack, I am doing this completely from memory and did not verify it completely in VS.Net. Some changes will probably be needed.
-
Jun 24th, 2003, 04:27 AM
#3
Sleep mode
Assuming you have two buttons :
VB Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click, Button2.Click
If sender Is Me.Button1 Then
MessageBox.Show("You clicked button1")
Else
MessageBox.Show("You clicked button2")
End If
End Sub
-
Jun 24th, 2003, 08:19 PM
#4
Thread Starter
Junior Member
(Resolved) How to capture Button Index in .NET
Hi Guys,
Thanks for the advise and help i manage to complete my assignment now 
Thanks a lot
regards
Jas
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|