PC Review


Reply
Thread Tools Rate Thread

Bringing a child form to the front

 
 
Richard L Rosenheim
Guest
Posts: n/a
 
      28th Oct 2004
I have the application's form (MainForm) along with a 2nd form (Form2). If
the user minimizes MainForm, I also minimize Form2. And when the user
restores the application, I also restore Form2. But, Form2 is ending up
behind MainForm. Anyone have an idea of how can I set/keep Form2 to be in
front of the MainForm?

And before someone suggests it, no -- I don't consider TopMost to be the
solution. That will make the form the topmost window for everything. I'm
trying to make Form2 the top most form only in relationship to MainForm.
Nor do I want to have a MDI application.

Here's the basic code I'm working with:

Private Sub MainForm_Resize(ByVal sender as Object, ByVal e as
System.EventArgs) Handles MyBase.Resize
If Me.WindowState = FormWindowState.Minimized Then
If Not (Form2 Is Nothing) Then
Form2.Visible = False
End If
Else
If Not (Form2 Is Nothing) Then
Form2.Visible = True
' code to bring Form2 to front goes here
End If
End If
End Sub

I did find the thread "Bring To Front of a Process/Other application"
http://groups.google.com/groups?hl=e...2522%26hl%3Den
but it's not working for me.

Based upon the above thread, I inserted the following code in the above code
fragment:

Dim handle As IntPtr = Form2.Handle
If Not IntPtr.Zero.Equals(handle) Then
Win32Helper.ShowWindow(handle, 1)
Win32Helper.SetForegroundwindow(handle)
End If

All I'm getting is Form2's windows briefly flashing in front of the main
form. BTW, I'm using Visual Studio 2004 on a Windows 2000 Pro machine.

Anyone have any suggestions?

Thanks in advance,

Richard Rosenheim


 
Reply With Quote
 
 
 
 
Ken Tucker [MVP]
Guest
Posts: n/a
 
      28th Oct 2004
Hi,

Form2.BringToFront
http://msdn.microsoft.com/library/de...fronttopic.asp

Ken
-------------------
"Richard L Rosenheim" <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
I have the application's form (MainForm) along with a 2nd form (Form2). If
the user minimizes MainForm, I also minimize Form2. And when the user
restores the application, I also restore Form2. But, Form2 is ending up
behind MainForm. Anyone have an idea of how can I set/keep Form2 to be in
front of the MainForm?

And before someone suggests it, no -- I don't consider TopMost to be the
solution. That will make the form the topmost window for everything. I'm
trying to make Form2 the top most form only in relationship to MainForm.
Nor do I want to have a MDI application.

Here's the basic code I'm working with:

Private Sub MainForm_Resize(ByVal sender as Object, ByVal e as
System.EventArgs) Handles MyBase.Resize
If Me.WindowState = FormWindowState.Minimized Then
If Not (Form2 Is Nothing) Then
Form2.Visible = False
End If
Else
If Not (Form2 Is Nothing) Then
Form2.Visible = True
' code to bring Form2 to front goes here
End If
End If
End Sub

I did find the thread "Bring To Front of a Process/Other application"
http://groups.google.com/groups?hl=e...2522%26hl%3Den
but it's not working for me.

Based upon the above thread, I inserted the following code in the above code
fragment:

Dim handle As IntPtr = Form2.Handle
If Not IntPtr.Zero.Equals(handle) Then
Win32Helper.ShowWindow(handle, 1)
Win32Helper.SetForegroundwindow(handle)
End If

All I'm getting is Form2's windows briefly flashing in front of the main
form. BTW, I'm using Visual Studio 2004 on a Windows 2000 Pro machine.

Anyone have any suggestions?

Thanks in advance,

Richard Rosenheim



 
Reply With Quote
 
No Sheds
Guest
Posts: n/a
 
      28th Oct 2004
In article <#(E-Mail Removed)>, Richard L Rosenheim
<(E-Mail Removed)> writes
>Anyone have an idea of how can I set/keep Form2 to be in
>front of the MainForm?


Will

form2.BringToFront

do it for you?

Regards
--
No Sheds
 
Reply With Quote
 
Richard L Rosenheim
Guest
Posts: n/a
 
      28th Oct 2004
It helps -- missed that method call.

Thanks.


"No Sheds" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> In article <#(E-Mail Removed)>, Richard L Rosenheim
> <(E-Mail Removed)> writes
> >Anyone have an idea of how can I set/keep Form2 to be in
> >front of the MainForm?

>
> Will
>
> form2.BringToFront
>
> do it for you?
>
> Regards
> --
> No Sheds



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Bringing second form to front when first gets focus (keeping both windows on top) papalarge Microsoft VB .NET 3 28th Feb 2007 10:30 PM
Bringing the last field in form to front in datasheet view =?Utf-8?B?TWFkaHVyaQ==?= Microsoft Access Form Coding 4 15th Jul 2005 11:08 AM
How to get in front MDI child form? Billy Microsoft VB .NET 2 3rd Dec 2004 03:38 PM
Bringing Form to Top/Front Kevin Carter Microsoft C# .NET 1 30th Oct 2003 11:30 AM
bringing form to Top/Front Kevin Carter Microsoft VB .NET 4 29th Oct 2003 11:47 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:20 PM.