为什么不创建一个带有事件的键盘控件并使用 WithEvents 键声明它?然后在键盘控件中声明以下事件:
Public Class CustomKeyboardControl
Inherits Control
Public Event KeyboardButtonPressed(ByVal KeyValue As String)
' ...
' And on click event for each of your buttons :
Private Sub BTN4_Click(sender As Object, e As EventArgs) Handles BTN4.Click
RaiseEvent KeyboardButtonPressed("4")
End Sub
End Class
最后,在使用此自定义键盘控件的应用程序中,只需添加一个处理程序。
Public Class MyForm
Private WithEvents MyKeyboard As New CustomKeyboardControl()
' Should be declared in your Designer...
' Just add the "WithEvents" if that declaration...
Private Sub HandleKeyboardInputs(ByVal KeyValue As String) Handles MyKeyboard.KeyboardButtonPressed
MyTextBox.Text = MyTextBox.Text + KeyValue
' Of course, you can use SelectionStart/SelectionLength (...)
' to replace or insert the input at the correct place
' without forgetting to update the values of SelectionStart and SelectionLength...
End Sub
' ...
End Class
这种方法让您可以在许多不同的情况下使用您的键盘控制...
希望这可以帮助。我可以看到您实际上正在使用类似 Android 的布局...在这种情况下,我认为我的想法不会更好...