我正在尝试制作自己的屏幕键盘 但我的代码有问题,看起来很长,请帮我简单地编写代码..
这是我的代码:
Dim kotak As Integer
Private Sub frmLogin_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
Private Sub txtUsernamePassword_GotFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtUsername.GotFocus, txtPassword.GotFocus
If txtUsername.Focused = True Then
kotak = 1
ElseIf txtPassword.Focused = True Then
kotak = 2
End If
End Sub
Private Sub btnQ_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnQ.Click
If kotak = 1 Then
txtUsername.Text = txtUsername.Text & btnQ.Text
ElseIf kotak = 2 Then
txtPassword.Text = txtPassword.Text & btnQ.Text
End If
End Sub
Private Sub btnW_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnW.Click
If kotak = 1 Then
txtUsername.Text = txtUsername.Text & btnW.Text
ElseIf kotak = 2 Then
txtPassword.Text = txtPassword.Text & btnW.Text
End If
End Sub
Private Sub btnE_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnE.Click
If kotak = 1 Then
txtUsername.Text = txtUsername.Text & btnE.Text
ElseIf kotak = 2 Then
txtPassword.Text = txtPassword.Text & btnE.Text
End If
End Sub
End Class
答案 0 :(得分:0)
为它制作一个子:
Private Sub AddLetter(ByVal letter As String)
If kotak = 1 Then
txtUsername.Text = txtUsername.Text & letter
ElseIf kotak = 2 Then
txtPassword.Text = txtPassword.Text & letter
End If
End Sub
Private Sub btnQ_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnQ.Click
AddLetter("Q")
End Sub
Private Sub btnW_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnW.Click
AddLetter("W")
End Sub
Private Sub btnE_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnE.Click
AddLetter("E")
End Sub
等等......