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
  • 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
VB.NET (2008) - Refactoring Question 2 24
HTML - Color not displaying correctly in EMAIL. 6 49
Help with exporting to excel 4 36
.NET 2008 VB and C# 6 39
Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
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…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below.…

860 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