Solved

What event to check when a Windows Forms regains focus?

Posted on 2014-03-11
5
249 Views
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?

Thanks!
0
Comment
Question by:BlakeMcKenna
  • 2
  • 2
5 Comments
 
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

0
 
LVL 9

Expert Comment

by:dustock
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

0
 

Author Comment

by:BlakeMcKenna
ID: 39921869
Carl,

I don't see a ChildFormClosed Event?
0
 
LVL 52

Accepted Solution

by:
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

0
 

Author Closing Comment

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

Thanks!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

911 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

Need Help in Real-Time?

Connect with top rated Experts

25 Experts available now in Live!

Get 1:1 Help Now