我一个form里有2个button
我想这个form为活动窗体时,回车就响应其中button1的Click事件。
不知道怎么实现?
各老大帮忙,谢谢!

解决方案 »

  1.   

    Private Sub button1_KeyPress(Index As Integer, KeyAscii As Integer)
        If KeyAscii = 13 Then
            End If
        End Sub
      

  2.   

    Private Sub Form_Activate()
       Command1.SetFocus
    End Sub
      

  3.   

    Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
        If KeyCode = vbEnter Then
             Command1_Click
        End If
    End Sub
      

  4.   

    Private Sub Form_Load()
      Form1.Show
      Command1.SetFocus
    End Sub
      

  5.   

    一般情况下设置  Command1.Default = True 
      

  6.   

    我觉得 xiaohuasz() ( ) 信誉:100 比较复合你的问题
    Lucky402() ( ) 信誉:100 进行过别的动作这后就不行了。
      

  7.   

    方法有两种: 
    1. 设置按钮的Default属性为True;
    2. 设置窗体的KeyPreview属性为True,并在KeyPress事件里进行处理Private Sub Form_KeyPress(KeyAscii As Integer)
        If KeyAscii = vbKeyReturn Then
             KeyAscii = 0         ' Handled
             Command1_Click
        End If
    End Sub
      

  8.   

    xjthief(神贼) ( ) 信誉:100 和 xiaohuasz() ( ) 信誉:100 是正解
      

  9.   

    设置按钮的Default属性为True即可