Keep a MDI child on top of other MDI children (C#)

Napivo1972

Regular
Joined
Aug 31, 2004
Messages
85
Here is what I want to do:

I have an MDI form and it has a tool dialog docked to the right side. I want to keep it on top of all other MDI child Forms and if possible remove the portion it takes from the MDI client frame.

Can anyone help me by explaining how I should do this?

Thanks in advance

Napivo

got this:

So what can you do ?

Here's how to set up an MDI application so that MDI childs operate normally, but some child windows always stay on top. (there is a simple trick … )

How do we’ll do it ?
1. The always-on-top child is not an MDI child ! – Don’t set its MdiPatent property
2. We will achieve the child’s behavior for this form by calling the win32 api SetParent( child.hwnd, parent.hwnd)

Follow these instructions to set up a simple demonstration:

1. Open visual studio
2. Create a windows application
3. Rename Form1 to MainForm and change the IsMdiContainer property to true.
4. Add two new Windows Forms to the project and name them frmMdiChild and frmAlwaysOnTop
5. Add the flowing lines to the MainForm load event:

frmMdiChild child1=new frmMdiChild();
child1.MdiParent=this;
child1.Show();

frmMdiChild child2=new frmMdiChild();
child2.MdiParent=this;
child2.Show();

frmAlwaysOnTop topform=new frmAlwaysOnTop();
topform.Show();
SetParent((int)topform.Handle,(int)this.Handle); <<< Here is the Magic :-)

6. Add declaration of the SetParent win32api to the MainForm class:
[DllImport("user32")] public static extern int SetParent(int hWndChild, int hWndNewParent) ;


The only problem is:

6. Add declaration of the SetParent win32api to the MainForm class:
[DllImport("user32")] public static extern int SetParent(int hWndChild, int hWndNewParent) ;


How can I do this in Microsoft Visual Studio 2008 Express?
 
What problem are you having? You should be able to paste it in as-is, regardless of which version of VS you are using.
 
Back
Top