• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 236
  • Last Modified:

lots of "handles x, y, z...." => Question

Hello

I have lots of buttons, and if I click on one, and I then press a key (1-9), the name of the button should change to the key-value.

I can do it like this:

Private Sub Button14_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Button14.KeyDown, Button15.KeyDown, Button16.KeyDown
        If e.KeyCode > 48 And e.KeyCode < 58 Then
            Button14.Text = e.KeyCode - 48
        End If
    End Sub

But in this example I have 3 buttons "handled", but how can I read in the code which button is "active"?

Thanks!

Sven
0
Ruttensoft
Asked:
Ruttensoft
2 Solutions
 
manchCommented:
Write in the following way :

Private Sub Button14_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Button14.KeyDown, Button15.KeyDown, Button16.KeyDown

       Dim pObjBtn as Button

       pObjBtn = Ctype(Sender, Button)

          If e.KeyCode > 48 And e.KeyCode < 58 Then
                pObjBtn.Text = e.KeyCode - 48
        End If

    End Sub
0
 
Éric MoreauSenior .Net ConsultantCommented:
Hi Ruttensoft,

You can check the sender like this:

if sender is Button14 then ...

Cheers!
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now