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

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
 
A

Armin Zingler

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
 
H

Herfried K. Wagner [MVP]

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
 

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

Top