Solved

What event to check when a Windows Forms regains focus?

Posted on 2014-03-11
5
247 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
Comment Utility
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
Comment Utility
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
Comment Utility
Carl,

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

Accepted Solution

by:
Carl Tawn earned 500 total points
Comment Utility
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
Comment Utility
For some reason that went right over the head...I tried it and that worked!

Thanks!
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

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…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

743 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

12 Experts available now in Live!

Get 1:1 Help Now