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

Ready to get started with anonymous questions?

It's easy! Check out this step-by-step guide for asking an anonymous question on Experts Exchange.

Question has a verified solution.

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

Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String ( Literal, only instead of starting and ending with w…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Suggested Courses

617 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