Textbox中输入文本时只有按回车键时才能保留,其他情况都返回原来值。求源代码用VB.net
1个回答
展开全部
Dim S As String
Private Sub TextBox1_KeyPress(sender As Object, e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
If e.KeyChar = vbCr Then
S = TextBox1.Text
End If
End Sub
Private Sub TextBox1_LostFocus(sender As Object, e As System.EventArgs) Handles TextBox1.LostFocus
TextBox1.Text = S
End Sub
Private Sub TextBox1_GotFocus(sender As Object, e As System.EventArgs) Handles TextBox1.GotFocus
S = TextBox1.Text
End Sub
'是这个意思不?
Private Sub TextBox1_KeyPress(sender As Object, e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
If e.KeyChar = vbCr Then
S = TextBox1.Text
End If
End Sub
Private Sub TextBox1_LostFocus(sender As Object, e As System.EventArgs) Handles TextBox1.LostFocus
TextBox1.Text = S
End Sub
Private Sub TextBox1_GotFocus(sender As Object, e As System.EventArgs) Handles TextBox1.GotFocus
S = TextBox1.Text
End Sub
'是这个意思不?
更多追问追答
追问
VB.net中显示无法找到keypress、lostfocus、getfocus事件哦~~~~
还有System.Windows.Forms.KeyPressEventArgs说未定义。。。。
追答
双击文本框(textbox),就可以找到三个事件。
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询