我正在通过VB.net处理Windows窗体。该表单包含两个文本框和一个我自己编程的屏幕键盘。
如何确定光标当前所在的文本框,以便屏幕键盘输入正确的文本框?
该应用程序旨在完全基于触摸。
答案 0 :(得分:0)
我猜你的屏幕键盘是一个代表键盘的系列按钮。
由于你有两个文本框,你必须为两个文本框都有一个标志,表示它们有焦点,当有一个文本框时,另一个没有。
Private Sub TextBox1_GotFocus(sender as Object, e as EventArgs) _
Handles TextBox1.GotFocus
// These flags are class level variables
textbox1HasFocus = true;
textbox2HasFocus = false;
End Sub
Private Sub TextBox2_GotFocus(sender as Object, e as EventArgs) _
Handles TextBox2.GotFocus
// These flags are class level variables
textbox2HasFocus = true;
textbox1HasFocus = false;
End Sub
用于键盘事件
Private Sub KeyBoard_Click(sender As Object, e As EventArgs) Handles ButtonA.Click, ButtonB.Click, ButtonC.Click, etc...
' I don't know how your using your keyboard, but buttonClickLetter could be determined in multiple ways. I would use either the Name of the control or even the Tag property for retrieving which letter to use
String buttonClickLetter = DirectCast(sender, Button).Tag.ToString()
If textbox1HasFocus Then
TextBox1.Text += buttonClickLetter
ElseIf textbox2HadFocus
TextBox2.Text += buttonClickLetter
End If
End Sub