473,695 Members | 2,603 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How do you bring MDI child windows to the front if MDI parent has controls?

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 MDI child window.

How can I make the MDI child window appear in front of any controls that may
be on the MDI parent?

thanks, John
Nov 21 '05 #1
2 14017
Here's what I found out so far.

When you specify that a form's property "IsMDIContainer " is true, the form
creates a "MDIclient" control. You can find that object with the following

For Each ctl As Control In Me.Controls

If TypeOf ctl Is MdiClient Then

Msgbox("we found an MDIclient and it's name is " & ctl.name)

End If


This MDIclient control is what contains the MDIchild forms. I repeat, the
main form DOES NOT contain the MDIchild forms, it contains an MDIclient
control and it's that control that contains the MDIchild forms.

This is exactly why if you change the background color of your main form
(ie: me.backcolor = color.blue) the background color of your MDIparent does
not change! If you want to change the background color of the MDIparent you
need to first find the MDIclient (as we did in the above code snippet) and
then do a:

Ctl.backcolor = color.blue

That will change the background color of the MDIparent to blue.

Since the MDIclient is just another control in VB you can do all the normal
things you can do with controls (this is important to understanding how MDI
works). Initially, the MDIclient control has it's DOCK property set to
"full". This is why it takes up all the space in your main form. It doesn't
have to! Remember, it's just a regular control. Also realize that if you
drag a control (say, a textbox or label) on to your main form it appears
that the control is going on to the MDIparent (because at design time the
DOCK property of the MDIclient is set to FULL), but it's not. The control
is actually going on to your main form.

This behavior is the cause of my original post. The MDIchild windows are
'behind' any control on the main form because the MDIclient object is behind
the other controls. Now, since MDIclient is just another control you can
send it to the front (BringToFront) however the side effect is that the
entire MDIclient control is brought to the front, and since it's dock
property is set to 'full', you can no longer see any of your other controls
(they're being hidden). So the best I can figure out now is that you can
actually reduce the size of the MDIclient control and put you other controls
in the part of the main form that the MDIclient doesn't occupy. When you
do this you will immediately see a problem. That is, the space on the main
form that is no longer occupied by the MDIclient control has a background
color of what's in Control Panel "applicatio n background" default (usually
dark grey), and setting your main form.backcolor doesn't affect it. So in
our code we need to create a panel that will occupy the space unoccupied by
MDIclient and set the panel's backcolor to whatever we want.

Let's look at an example: Say that you have created some sort of custom
menubar that you want to put on your main form (so it's always available
regardless of any MDIchild windows that may be open). And assume that this
menubar will be on the top part of your screen. What we need to do is size
the MDIclient control so that there is room for your menubar.

Assume that your menubar takes up 50 pixels in height, and that you want
both the main form and your MDIclient control to have a background color of
light blue. Here's the code that does it:

Private Sub Form1_Load(ByVa l sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load

Dim pnl As New Panel

pnl.Width = Me.Width

pnl.Anchor = AnchorStyles.Le ft Or AnchorStyles.Ri ght Or
AnchorStyles.To p

pnl.Height = 57 '2 pixels bigger than needed to cover the border
of the MDIclient control

pnl.Location = New Point(0, 0) 'your panel is on the top of the

pnl.BackColor = Color.PowderBlu e

Me.Controls.Add (pnl)

' Loop through all of the form's controls looking

' for the control of type MdiClient.

For Each ctl As Control In Me.Controls

If TypeOf ctl Is MdiClient Then

ctl.BackColor = Color.PowderBlu e

ctl.Width = Me.Width

ctl.Height = Me.Height

ctl.Location = New Point(0, 55) 'this gives you room at
the top

ctl.Anchor = AnchorStyles.Le ft Or AnchorStyles.Bo ttom Or
AnchorStyles.Ri ght Or AnchorStyles.To p

End If


Me.BackColor = Color.PowderBlu e

Dim frmChild As New Form 'now create a MDIchild form

frmChild.MdiPar ent = Me


End Sub

What you get when you put this code into your main form's LOAD event is a
uniformly power blue form with a child window that can't be moved any closer
than 55 pixels from the top of the main form. The anchor properties keep
everything looking good as you grow and shrink the main form and the child

Hope this helps to clear up how MDI works. And if anybody has a way to
solve the my original problem of having controls show up above the MDIclient
but below the MDIchild forms I'd appreciate hearing about it.

"JohnR" <Jo******@hotma il.com> wrote in message
news:wo9ce.4060 $u56.933@trndny 09...
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 MDI child window.

How can I make the MDI child window appear in front of any controls that
may be on the MDI parent?

thanks, John

Nov 21 '05 #2
That was good analysis about the MDI forms.

I was playing around and the code that I came up w/ is really rudimentary.
The drawbacks of what I have done are

(a) It is not dynamic in nature; i.e. all the controls are on the parent are
hidden when the MDI Child form is shown and made visible when the child is

(b) everytime you minimise the child form to wrok on the parent you would
have to make the controls visible.

Anyways, here is my silly code.

Dim obj As Object
'Place this code before or after the show method of the MDIchild
For Each obj In Me.Controls
If obj.GetType.Ful lName <> "System.Windows .Forms.MdiClien t" Then
obj.Visible = False
End If
Next obj

Nov 21 '05 #3

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

Similar topics

by: jrefactors | last post by:
>From the main page, there are lots of links to open new window. i.e. <a href="#" onClick="window.open('child1.html')">Open Child Window</a> If I close the main page, I want to close all child windows also. That means I need to keep track all handles of the child windows whenever I open a new window. Correct? any suggestions on the approach? Please advise. thanks!!
by: Randell D. | last post by:
Folks, I'm working on a contact name/address database whereby a slimed down list is shown in the main window. When a record is selected, the complete record is displayed in a new window via a call to window.open As opposed to closing and re-opening new windows, I would prefer that when the user is finished reading the complete record, they can click a link whereby the main window is sent in to focus.
by: Bonj | last post by:
Further to my last post, I have managed to get a child window to display. But its messages are routed to the same WNDPROC that the main window's messages are routed to - what is the way of identifying from the lParam or wParam whether the message came from a child window or the parent? And what if the message uses some other data in the wParam or lParam? Is it better to use one wndproc for the parent window, and one wndproc for all child windows...
by: Isabel | last post by:
How can you close all child browser windows that where open by a parent browser window? I have links on a parent (main) page that opens the child page as a separate browser. However, I need to be able to close all the opened child browser pages from the parent page. Thank you for your help, Isabel
by: Arulraja | last post by:
Hello, I have created 2 custom server controls, The parent custom control contains multiple child custom controls. The Child control has a button on it. If I Click the button control, it calls the Parent controls CreateChildControls() method before calling the child control's button click event. Because of this behaviour, I am not getting the changes I made in the
by: Bill Borg | last post by:
Hello all, Simple chat app, where the site owner has a master window with all requests for chat, status of each room, etc., and child windows for each separate chat in which the owner is engaged. When the owner closes one of his child windows, I want to update the master window. I understand "reasonably" well how to go about this. The master window launches the children, and maintains an associative array to keep track of each one....
by: lotus | last post by:
HI All.. I'm realtively new to C#. I have MainForm which includes Parent usercontol, and this parent usercontrol also contains child usercontrol. MainForm --> Parent usercontrol --> child usercontrol Parent usercontol has one button to change the child usercontorl's variable.
by: diego | last post by:
Hello everyone. I have an MDI form (parent) that has a number of controls on it. When I display MDI child windows, the child windows appear behind the controls that are on the parent window. How can make it so that the child window are on top of the controls on the parent window. Thanks in advance. Diego
by: zEE | last post by:
How to close all the child windows when parent window get closed? in ASP.net application through scripting..
by: zybernau | last post by:
hi, all in javascript i need to close all the child windows that i have opened through a parent window scenario: * here i will be having as many as child window opened and name given to the child window can not be tracked because each will be having a different name, and * i am using 70 to 80 popup windows through out my page * there can be any number of child windows opened , at the time of user triGgers the event from...
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.