How to set Focus on a control AFTER a ShowDialog call?

  • Thread starter Thread starter Ed
  • Start date Start date
E

Ed

I have 2 forms:

Form1 calls Form2 via a Form2.ShowDialog(me) call. However, after
Form2 appears, I want to set the focus to a specific control, but I
can't. Does anyone know how to do this?

Thanks,
ed
 
Is it necessary to post to all these groups?
I have 2 forms:

Form1 calls Form2 via a Form2.ShowDialog(me) call. However, after
Form2 appears, I want to set the focus to a specific control, but
I can't.
Why?

Does anyone know how to do this?

Either set the tab order at design time, or use the following code:

Protected Overrides Sub OnActivated( _
ByVal e As System.EventArgs)

Static done As Boolean

MyBase.OnActivated(e)

If Not done Then
done = True
TheControl.Focus()
End If

End Sub
 
Hello,

Ed said:
Form1 calls Form2 via a Form2.ShowDialog(me) call. However, after
Form2 appears, I want to set the focus to a specific control, but I
can't. Does anyone know how to do this?

1. I hate X-Posts.
2. The focus will be set to the control with the smallest TabIndex value.
Maybe you want to set the controls' TabIndex properties.

HTH,
Herfried K. Wagner
 
Back
Top