Solved

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

Posted on 2006-06-21
4
212 Views
Last Modified: 2010-04-23
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
Comment
Question by:Ruttensoft
4 Comments
 
LVL 6

Accepted Solution

by:
manch earned 250 total points
Comment Utility
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
 
LVL 69

Assisted Solution

by:Éric Moreau
Éric Moreau earned 250 total points
Comment Utility
Hi Ruttensoft,

You can check the sender like this:

if sender is Button14 then ...

Cheers!
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Suggested Solutions

I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
This video discusses moving either the default database or any database to a new volume.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now