用下面这段代码试试:
Private Sub Command1_Click()
Text1.Text = ""
Text1.SetFocus
End SubPrivate Sub Form_Load()
Command1.SetFocus
End SubPrivate Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
Command1.SetFocus
End If
End Sub
Private Sub Command1_Click()
Text1.Text = ""
Text1.SetFocus
End SubPrivate Sub Form_Load()
Command1.SetFocus
End SubPrivate Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
Command1.SetFocus
End If
End Sub
2、Private Sub button1_click()
text1.text=""
text1.setfocus
end sub
Private Sub Command1_Click() '一个Button按钮
MsgBox "sf"
End SubPrivate Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
If Key = 13 Then
Call Command1_Click
End If
End Sub在窗体上按下回车键相当于点击Command1按钮
Text1.Text = ""
Text1.SetFocus
End Sub
private sub form_keypress(keyascii as integer)
if keyascii=13 then
command1_click
end if
end sub
第二个问题:
private sub command1_click
text1.text=""
text1.setfocus
end sub
其实这2者可以合成,实现当输完后按回车的效果:
Private Sub Text1_KeyPress(KeyAscii As Integer)
text1.text=""
text1.setfocus
End Sub