If KeyAscii = 13 Then
cbs_name.SelStart = 0
cbs_name.SelLength = Len(cbs_name.Text)
End If有时这个不生效,这个写法有问题吗?

解决方案 »

  1.   

    If KeyAscii = 13 Then
    cbs_name.setfocus
    cbs_name.SelStart = 0
    cbs_name.SelLength = Len(cbs_name.Text)
    End If
    试下
    你是在哪判断KeyAscii的?
      

  2.   

    先把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
      

  3.   

    "先把form的keyPreview属性设为true  "
     这个在哪设?
      

  4.   

    form设了true,我的form里有5个文本框,都不行啊
      

  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
      

  6.   

    那就分别:
    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时,回车能行的(我试了)
      

  7.   

    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