E
E
Elz2016-09-12 07:27:21
Visual Basic
Elz, 2016-09-12 07:27:21

How to select focused element in VB.net?

I've only been doing VB.net for a couple of days and now I'm making a calculator.
So, I want that when you click on the button, let's say "1", in the TextBox on which the focus is, this number is entered.
Help with focus.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alex Andr, 2017-02-17
@Ksardas

If I understand correctly, then:

'У формы ставишь свойство
KeyPreview = True

'На событие KeyUp
Private Sub Form1_KeyUp(sender As Object, e As KeyEventArgs) Handles MyBase.KeyUp
    Select Case e.KeyCode
        Case Keys.D1, Keys.NumPad1
            TextBox1.Text &= 1
        Case Keys.D2, Keys.NumPad2
            TextBox1.Text &= 2
        '...'
        Case Keys.Back
            If TextBox1.Text.Length > 0 Then TextBox1.Text = TextBox1.Text.Substring(0, TextBox1.Text.Length - 1)
    End Select
End Sub

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question