try
复制程式
Public Class Form3
Dim r As New Random
Dim i As Integer
Private Sub Text1_KeyPress(ByVal KeyAscii As Integer)
If KeyAscii = i Then
TextBox1.text = ""
KeyAscii = 0
i = r.Next(65, 90)
Label1.Text = Chr(i)
End If
End Sub
Private Sub Form3_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
i = r.Next(65, 90)
Label1.Text = Chr(i)
End Sub
End Class
KeyAscii = 0
这个漏了...pass是在[键盘输入]跟[显示在物件上面]两事件之间
只有TextBox1.text = ""没用...
因为:
[键盘输入]
↓
[pass事件] 这时候TextBox1.text = ""
↓
[显示在物件上面]这里又会把KeyAscii转成字元显示在TextBox1上
所以KeyAscii=0也要
如果还是不行请描述一下哪里不ok
比方说
"输入跟LABEL一样的自之后TEXTBOX没有变成空白"
或是
"LABEL的字都只出现一种"
或是
"TEXTBOX输入跟LABEL一样的字,LABEL还是都不会改变"
之类的...这样要侦错比较快