What event to check when a Windows Forms regains focus?

Posted on 2014-03-11
Last Modified: 2014-03-11
I have a situation where I have a form open but based on a users action, another form will be opened in which they can retrieve a record from the database via a DataGridView. Once a record is selected, that data record will populate the parent Form but what event to I check that fires when the child form is closed indicating the parent form has focus again?

Question by:BlakeMcKenna
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
LVL 52

Expert Comment

by:Carl Tawn
ID: 39921103
Assuming you are launching the child form from your parent form, and holding a reference to it, you can hook in to the Form_Closing/Form_Closed events:
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load

    Dim childForm As Form2 = New Form2()
    AddHandler childForm.FormClosed, AddressOf ChildFormClosed

End Sub

Private Sub ChildFormClosed(sender As Object, e As System.Windows.Forms.FormClosedEventArgs)
    MsgBox("Child closed")
End Sub

Open in new window


Expert Comment

ID: 39921120
You can assign the DialogResult to buttons on your second from and then do something like this

        Dim frm As New Form1()

        If frm.ShowDialog() = DialogResult.OK Then

        End If

Open in new window


Author Comment

ID: 39921869

I don't see a ChildFormClosed Event?
LVL 52

Accepted Solution

Carl Tawn earned 500 total points
ID: 39921990
In the code above, ChildFormClosed isn't the event, it's the eventhandler method. The event is FormClosed - as in the line:
 AddHandler childForm.FormClosed, AddressOf ChildFormClosed

Open in new window


Author Closing Comment

ID: 39922002
For some reason that went right over the head...I tried it and that worked!


Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
Introduction When many people think of the WebBrowser ( control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question