简体   繁体   中英

make enter button of textbox

i have textbox multi way to fill it i can fill it from keyboard normally and the other way by clicking button i created on forum something like calculator

when i click button 1 the textbox fill by number 1 and so and i have button name and work should be like enter key

i have event keydown to send the value i fill it on the text box and work fine but i need the button that called enter work as the event keydown of the textbox

in short word i need to use touchscreen to enter number to textbox and button to send the value of the textbox to my work

If you want to execute the same code at two different occasions you should put your code in a separate method and then call that at will.

By dividing your code like this you improve both readability and debuggability, and you make your code easier to understand and update.

Here's a brief example:

Private Sub TextBox1_KeyDown(sender As Object, e As System.Windows.Input.KeyEventArgs) Handles TextBox1.KeyDown
    If e.Key = Key.Enter Then
        UpdateStatus("Enter was pressed.") 'Call custom method.
    End If
End Sub

Private Sub Button1_Click(sender As System.Object, e As System.Windows.RoutedEventArgs) Handles Button1.Click
    UpdateStatus("Button1 was pressed. Hello World!") 'Call custom method.
End Sub

Private Sub UpdateStatus(ByVal Text As String) 'Custom method declaration.
    TextBox1.Text = Text
    'In here is where you'd put your code.
End Sub

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM