473,396 Members | 1,766 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Bringing a child form to the front

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
Nov 21 '05 #1
3 3197
Hi,

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

Ken
-------------------
"Richard L Rosenheim" <ri*****@rlr.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
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

Nov 21 '05 #2
In article <#5**************@TK2MSFTNGP09.phx.gbl>, Richard L Rosenheim
<ri*****@rlr.com> 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
Nov 21 '05 #3
It helps -- missed that method call.

Thanks.
"No Sheds" <me@privacy.net> wrote in message
news:i2**************@heaser.com...
In article <#5**************@TK2MSFTNGP09.phx.gbl>, Richard L Rosenheim
<ri*****@rlr.com> 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

Nov 21 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Terry | last post by:
when using one form - i can set the z-order. Is there a way programatically to create a "z-order" across .exe. I have 2 .exe - one that paints a background form and then another that fills in...
0
by: clu82 | last post by:
I have an MDI app that allows the user to open multiple client address child forms. The user has a child form open that has client id "1001" and the records associated data displayed. If the user...
2
by: zobie | last post by:
In the parent of my MDI application I declare a child form private frmChild = null; which is to be activated on a menu click. In the click event I am using the following code: if (frmChild...
1
by: zbcong | last post by:
hello if there are several child forms are opened in their mdi parent.how can i move the one of the child forms to the front end to show in the CODE?? thank you!!!
0
by: Beenish Sahar Khan | last post by:
I'm working on a C# application(2003.) I have an MDI form which contains multiple MDI children, i want to bring an MDI child in the front and make it the top most form. As you can see, i want it to...
4
by: Kevin Carter | last post by:
Hi there...hoping somebody can help me out because I am almost ready to pull out my hair. My problem is as follows: In a method in my main form (non MDI app), I instantiate and .Show another...
7
by: Siv | last post by:
Hi, I have an MDI application that uses a generic "ShowPage" routine in a module that is called when I want to display a child form. The basic idea is that in the module I have declared each form...
2
by: JohnR | last post by:
Let's say I have an MDI parent form with a textbox. If I create an MDI child form and, at runtime, move the MDI child window over the textbox on the MDI parent, the textbox appears in front of the...
3
by: O.B. | last post by:
I have a form that shows another child form using the Show() operation. Since the child is modaless, I would like the option that when I click anywhere on the parent form that the parent form...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.