Joseph Goh Joseph Goh - 1 year ago 90
Vb.net Question

Set focus to text after closing modal form

I am trying to create an application using VB NET and trying to figure out how to achieve what i wanted but seems i stuck there.

I have

Form1
with
Button1
and
Textbox1
, when we clicked on
Button1
, it will open
Form2
modally
Form2.ShowDialog()
. Now after
Form2
closed, i would like to set
Textbox1
in
Form1
.

So far what i have tried is to put
Form1.Textbox1.Select()
method in
Form2
both in
FormClosed
and
FormClosing
event, but it does not worked. And then tried to put
Me.Textbox1.Select
method in
Form1
Activated
event does not worked as well.

Any idea how to do this?

Answer Source

Given that this is how you call it in Button1:

Form2.ShowDialog()

You can simply put:

TextBox1.Focus() after Form2.ShowDialog() so that when Form2 was closed, TextBox1 will be focused on Form1.

As simple as this:

Form2.ShowDialog()
TextBox1.Focus()

When you call a ShowDialog(), it will not proceed to the next code until that form was closed.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download