一个文本框如何当按下回车键, 执行一个函数?

解决方案 »

  1.   

    在keydown中写一个函数捕捉 chr(13)号键
      

  2.   

    Private Sub Text1_KeyPress(KeyAscii As Integer)
    If KeyAscii = 13 Then
    'call 函数
    End If
    End Sub
      

  3.   

    例如:Private Sub Text1_KeyPress(KeyAscii As Integer)
            If KeyAscii = 13 Then
               Text1 = MYFUN(Val(Text1))
               KeyAscii = 0
            End If
    End Sub
    Function MYFUN(A As Long) As Long
             MYFUN = A ^ 2
    End Function