If KeyAscii = 13 Then cbs_name.setfocus cbs_name.SelStart = 0 cbs_name.SelLength = Len(cbs_name.Text) End If 试下 你是在哪判断KeyAscii的?
先把form的keyPreview属性设为true Private Sub Form_KeyPress(KeyAscii As Integer) If KeyAscii = 13 Then Text1.SetFocus Text1.SelStart = 0 Text1.SelLength = Len(Text1.Text) End If End Sub
"先把form的keyPreview属性设为true " 这个在哪设?
form设了true,我的form里有5个文本框,都不行啊
将5个文本框设为控件数组Private Sub Text1_KeyPress(index As Integer, KeyAscii As Integer) If KeyAscii = 13 Then Text1(index).SelStart = 0: Text1(index).SelLength = Len(Text1(index)) End Sub
那就分别: Private Sub Text1_KeyPress(KeyAscii As Integer) If KeyAscii = 13 Then Text1.SetFocus Text1.SelStart = 0 Text1.SelLength = Len(Text1.Text) End If End Sub当你焦点在text1时,回车能行的(我试了)
1.请不要在此事件发生后又把当前的TextBox的焦点移走(不论是写在哪里) 2.TextBox的Multiline不能是True,如果非要设成True,那么: Private Sub Text1_KeyPress(KeyAscii As Integer) If KeyAscii = 13 Then KeyAscii = 0 Me.Text1.SelStart = 0 Me.Text1.SelLength = Len(Me.Text1.Text) End If
cbs_name.setfocus
cbs_name.SelStart = 0
cbs_name.SelLength = Len(cbs_name.Text)
End If
试下
你是在哪判断KeyAscii的?
Private Sub Form_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
Text1.SetFocus
Text1.SelStart = 0
Text1.SelLength = Len(Text1.Text)
End If
End Sub
这个在哪设?
If KeyAscii = 13 Then Text1(index).SelStart = 0: Text1(index).SelLength = Len(Text1(index))
End Sub
Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
Text1.SetFocus
Text1.SelStart = 0
Text1.SelLength = Len(Text1.Text)
End If
End Sub当你焦点在text1时,回车能行的(我试了)
2.TextBox的Multiline不能是True,如果非要设成True,那么:
Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
KeyAscii = 0
Me.Text1.SelStart = 0
Me.Text1.SelLength = Len(Me.Text1.Text)
End If