Closing owned form pushes main app to background

  • Thread starter Thread starter Joel Moore
  • Start date Start date
J

Joel Moore

I'm trying to add a child form to my main application form. It looks
like the Owner property of the child form does what I need (or the
AddOwnedForm method of the parent form -- same thing).

It works nice but when I close the child form my main application loses
focus to one of the other open applications. I thought it was random
which app got the focus but it appears if I keep reopening and closing
the child form all the open applications eventually get a turn (in
whatever order they're in in the ALT-TAB window).

Obviously this isn't acceptable.

Here's what I'm doing:

Within the Click event for a button on my Main form I have the following:

Dim child As New childForm
child.Owner = Me
child.Show()

When the child form closes I don't do anything to remove it from the Main
form's owned list. I figure this is taken care of automatically.
Regardless I tried adding "Me.Owner = Nothing" to the Closing event of
the Child form which made no difference.

I'm developing in VS.NET 2003 with on XP Pro with the latest updates.

Thanks,

Joel Moore
 
Hi Joel,

In your Child's Closing event put this line

this.Owner.BringToFront(); // or Me.Owner.BringToFront();


Happy coding!
Morten Wennevik [C# MVP]
 
Hi Joel,

In your Child's Closing event put this line

this.Owner.BringToFront(); // or Me.Owner.BringToFront();


Happy coding!
Morten Wennevik [C# MVP]

I love the quick answers! Thanks, that worked great. In hindsight that
should have been obvious.
 
Back
Top