Why does this work?

  • Thread starter Thread starter DazedAndConfused
  • Start date Start date
D

DazedAndConfused

I have an MDI application.

1) When there are multiple forms open
2) And the form with focus is changed using the mouse,
3) When focus is returned to a form that previously had focus
4) And the Tab key is hit to go to the next control on the form, the Validating event does not fire for the control that has focus on the form.

The form has a routine that is used to tab to the next control when the Return key is hit.

So I tried this to see what would happen:

Private Sub frmMortgage_Enter(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Enter
Dim ctrl As Control
ctrl = Me.ActiveControl

If Not ctrl Is Nothing Then
ChangeFocus(ctrl.TabIndex)
End If

End Sub

Stepping through the code I can see focus change to the next control, BUT when the form is displayed the focus is on the original control.

Why?

Focus is exactly where I want it, but I was expecting to have to force it back to the previous control on the form.

Is this a really bad way of getting what I want?

Is there a better way without using the KeyUp or KeyDown events on the Tab key(I have reasons I don't want to use them)?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top