How do I focus a TextBox element on the main form after closing a second form which is opened by calling ShowDialog()?
I have tried to call MainForm.TextBox.Focus() in the closing and closed event of the second form, but this won’t focus the textbox.
I am using System.Windows.Forms on the compact framework.
Thanks.
From your second form, make a button (or another control) return a
DialogResultby going into Properties. When you want the second form to close (ie after you press a button) make it return a specificDialogResult. In your main form you can do this:Calling
ShowDialog()will block until it is closed so you could simply do:However the first example is for when you only want to make the textbox have focus after you press a certain button or do an action on the second form.