Home All Groups Group Topic Archive Search About

How can An MDI child form stay on top ?

Author
7 Jun 2009 7:15 PM
rony g
Hi All
I have an mdi form with serveral mdi child forms.
How can I set one mdi child form so that it always
stay on top ?

Thanks
Rony



*** Sent via Developersdex http://www.developersdex.com ***

Author
7 Jun 2009 9:44 PM
MikeD
"rony g" <nospam> wrote in message
news:uw2RcR65JHA.1716@TK2MSFTNGP03.phx.gbl...
> Hi All
> I have an mdi form with serveral mdi child forms.
> How can I set one mdi child form so that it always
> stay on top ?
>


For what possible reason would you want to do that? That's completely
against what MDI is for.

--
Mike
Author
8 Jun 2009 11:46 AM
Jan Hyde
"MikeD" <nob***@nowhere.edu>'s wild thoughts were released
on Sun, 7 Jun 2009 17:44:13 -0400 bearing the following
fruit:

>
>"rony g" <nospam> wrote in message
>news:uw2RcR65JHA.1716@TK2MSFTNGP03.phx.gbl...
>> Hi All
>> I have an mdi form with serveral mdi child forms.
>> How can I set one mdi child form so that it always
>> stay on top ?
>>
>
>
>For what possible reason would you want to do that? That's completely
>against what MDI is for.

Posibly for a side bar type menu thing. Either way, the OP
is going the wrong way about it.


--
Jan Hyde
Author
7 Jun 2009 11:00 PM
Randem
Why would you want to do that? As MikeD stated it is against what MDI is
for. But if you really want to do the absurd you will need to basically get
a timer to bring that form to focus constantly...

--
Randem Systems
Your Installation Specialist
The Top Inno Setup Script Generator
http://www.randem.com/innoscript.html
Disk Read Error Press Ctl+Alt+Del to Restart
http://www.randem.com/discus/messages/9402/9406.html?1236319938



Show quoteHide quote
"rony g" <nospam> wrote in message
news:uw2RcR65JHA.1716@TK2MSFTNGP03.phx.gbl...
> Hi All
> I have an mdi form with serveral mdi child forms.
> How can I set one mdi child form so that it always
> stay on top ?
>
> Thanks
> Rony
>
>
>
> *** Sent via Developersdex http://www.developersdex.com ***
Author
8 Jun 2009 12:32 PM
Larry Serflaten
"rony g" <nospam> wrote
> Hi All
> I have an mdi form with serveral mdi child forms.
> How can I set one mdi child form so that it always
> stay on top ?

How about you add a Picutrebox to one edge of the MDI parent
and put your controls on that?

LFS
Author
8 Jun 2009 1:39 PM
Jeff Johnson
"rony g" <nospam> wrote in message
news:uw2RcR65JHA.1716@TK2MSFTNGP03.phx.gbl...

> I have an mdi form with serveral mdi child forms.
> How can I set one mdi child form so that it always
> stay on top ?

You can't. You need to use something other than an MDI child for this.
Author
9 Jun 2009 3:42 PM
Chris
Going against what all the other replies say, I also have a use for this
from time to time.  Our application basically hosts all forms within an MDI
container.  Most forms are general input entry forms and grids etc, but I
occasionally want a window to stay on top of all the others that are open.
E.g. When I have a booking form open I want another small window open with
the basic clients details visible for various purposes.  It's a small Fixed
ToolWindow form in the bottom right.  I think something like this a great
use.  It may not be a MDI child in the normal sense, but might be the kind
of thing you were referring to.


Firstly make sure the MDIChild is set to False

In the declarations at the top of the form...

    Private Declare Function SetParent Lib "user32" (ByVal hWndChild As
Long, ByVal hWndNewParent As Long) As Long
    Private Declare Function SetForegroundWindow Lib "user32" (ByVal hwnd As
Long) As Long

In form load set the following...

    SetParent Me.hwnd, frmMain.hwnd
    SetForegroundWindow Me.hwnd

frmMain should be set to the name of the MDI parent.  Even though the form
is set to an MDIChild it will still stay within the bounds of the MDI parent
with the above code.

Hope this helps.

Chris




Show quoteHide quote
"rony g" <nospam> wrote in message
news:uw2RcR65JHA.1716@TK2MSFTNGP03.phx.gbl...
> Hi All
> I have an mdi form with serveral mdi child forms.
> How can I set one mdi child form so that it always
> stay on top ?
>
> Thanks
> Rony
>
>
>
> *** Sent via Developersdex http://www.developersdex.com ***
>
Author
9 Jun 2009 7:45 PM
Jeff Johnson
"Chris" <cw@community.nospam> wrote in message
news:u0bbYjR6JHA.1424@TK2MSFTNGP02.phx.gbl...

> frmMain should be set to the name of the MDI parent.  Even though the form
> is set to an MDIChild it will still stay within the bounds of the MDI
> parent with the above code.

There's no "even though" about it. That's the NORMAL behavior of an MDI
child.
Author
10 Jun 2009 2:47 PM
Chris
I actually meant to say "Even though the forms MDIChild is set to False it
will stay in the bounds of the MDI parent".

The API call makes the form stay within the MDI window even though MDIChild
is set to False.

I don't want to argue about whether you should allow "always on top" with
MDI Children.  I was just trying to help someone out who might have a
similar need for it as me.  For my application it works perfectly.  Having
an MDI parent to host all forms works great.

One example of where others have used this is in VB6 itself.  If you run VB6
in MDI mode... if you undock the Immediate window as you drag it around it
always stays on top of the code windows.  Perfect use of it!

Chris


Show quoteHide quote
"Jeff Johnson" <i.get@enough.spam>
>> frmMain should be set to the name of the MDI parent.  Even though the
>> form is set to an MDIChild it will still stay within the bounds of the
>> MDI parent with the above code.
>
> There's no "even though" about it. That's the NORMAL behavior of an MDI
> child.
>
>
Author
10 Jun 2009 6:37 PM
Jeff Johnson
Show quote Hide quote
"Chris" <cw@community.nospam> wrote in message
news:e4aGrpd6JHA.2456@TK2MSFTNGP02.phx.gbl...

>I actually meant to say "Even though the forms MDIChild is set to False it
>will stay in the bounds of the MDI parent".
>
> The API call makes the form stay within the MDI window even though
> MDIChild is set to False.
>
> I don't want to argue about whether you should allow "always on top" with
> MDI Children.  I was just trying to help someone out who might have a
> similar need for it as me.  For my application it works perfectly.  Having
> an MDI parent to host all forms works great.
>
> One example of where others have used this is in VB6 itself.  If you run
> VB6 in MDI mode... if you undock the Immediate window as you drag it
> around it always stays on top of the code windows.  Perfect use of it!

But the Immediate window is not an MDI child, and it CAN be dragged outside
of the MDI parent. That's the point I was trying to make: if you want this
functionality you must not use an MDI child (the definition under VB being
"a form with the MDIChild property set to True"). Plus I think limiting the
movement of such a form to the parent is just silly. Has anyone ever used a
program that did this? What was the justification?
Author
16 Jun 2009 6:08 PM
Marc-Andre Paquette
Hi Chris, thanks for your post, I need this kind of behavior in my
application too. I tried to put the code exactly as you mentionned and I
get errors.

Public Class test
    Private Declare Function SetParent Lib "user32" (ByVal hWndChild As
Long, ByVal hWndNewParent As Long) As Long
    Private Declare Function SetForegroundWindow Lib "user32" (ByVal
hwnd As Long) As Long

    Private Sub test_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

        Try
            SetParent(Me.hwnd, Magentis.hwnd)
            SetForegroundWindow(hwnd)
        Catch ex As Exception

        End Try
    End Sub
End Class

This is what I did and the error is : 'hwnd' is not declared.

Any ideas what I did wrong?

Thanks
Marc-Andre

*** Sent via Developersdex http://www.developersdex.com ***
Author
18 Jun 2009 8:28 AM
Chris
Hi Marc-Andre,

I assume from your code you are trying this in VB.NET?  I've never tried it
in there before.  My example was for VB6 and I would not know if this is
possible in .NET.

Thanks,
Chris



Show quoteHide quote
"Marc-Andre Paquette" <marc-andre.paque***@videotron.ca> wrote in message
news:%23cLbF2q7JHA.4376@TK2MSFTNGP06.phx.gbl...
>
>
> Hi Chris, thanks for your post, I need this kind of behavior in my
> application too. I tried to put the code exactly as you mentionned and I
> get errors.
>
> Public Class test
>    Private Declare Function SetParent Lib "user32" (ByVal hWndChild As
> Long, ByVal hWndNewParent As Long) As Long
>    Private Declare Function SetForegroundWindow Lib "user32" (ByVal
> hwnd As Long) As Long
>
>    Private Sub test_Load(ByVal sender As System.Object, ByVal e As
> System.EventArgs) Handles MyBase.Load
>
>        Try
>            SetParent(Me.hwnd, Magentis.hwnd)
>            SetForegroundWindow(hwnd)
>        Catch ex As Exception
>
>        End Try
>    End Sub
> End Class
>
> This is what I did and the error is : 'hwnd' is not declared.
>
> Any ideas what I did wrong?
>
> Thanks
> Marc-Andre
>
> *** Sent via Developersdex http://www.developersdex.com ***
>
Author
19 Jun 2009 3:51 PM
Jeff Johnson
"Marc-Andre Paquette" <marc-andre.paque***@videotron.ca> wrote in message
news:%23cLbF2q7JHA.4376@TK2MSFTNGP06.phx.gbl...

>    Private Sub test_Load(ByVal sender As System.Object, ByVal e As
> System.EventArgs) Handles MyBase.Load

[Canned response]

This is a VB "classic" newsgroup. Questions about VB.NET (including VB
2005/2008 and VB Express, which have dropped .NET from their names) are
off-topic here.

Please ask .NET questions in newsgroups with "dotnet" in their names. The
*.vb.* groups are for VB6 and earlier. If you don't see the *.dotnet.*
groups on your news server, connect directly to the Microsoft server:
msnews.microsoft.com.

For questions specific to the VB.NET language, use this group:

microsoft.public.dotnet.languages.vb

Please note that things like controls and data access, which have their own
subgroups in the Classic VB hierarchy, are not language-specific in .NET, so
you should look for groups like these:

microsoft.public.dotnet.framework.windowsforms.controls
microsoft.public.dotnet.framework.adonet

(Note that "vb" is not present in the group name.)