when a form is loaded, how to set focus at a control which has the smallest tabindex? if you will pls show coding to me ,thanks a lot

解决方案 »

  1.   

    焦点不是可以自动落在tabindex最小的控件上吗?
      

  2.   

    在load事件中,可以加上  ***.setfocus就行。
      

  3.   

    Private Sub Form_Activate()
        ***.setfocus
    End Sub
      

  4.   

    but if I do not know which control is disable,which is enable ,how can I set focus?
    using activecontrol is right?how to use it?
      

  5.   

    Private Sub Form_Activate()
        Dim ctl As Control
        For Each ctl In Me.Controls
            If ctl.Enabled Then
                ctl.SetFocus
            End If
        Next
    End Sub
      

  6.   

    Private Sub Form_Activate()
        Dim ctl As Control
        Dim ctlSmallTab As Control
        Set ctlSmallTab = Me.Controls(0)
        For Each ctl In Me.Controls
            
            If ctl.TabIndex < ctlSmallTab.TabIndex And ctl.Enabled Then
                Set ctlSmallTab = ctl
            End If
        Next
        ctlSmallTab.SetFocus
        
    End Sub