473,372 Members | 1,114 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,372 software developers and data experts.

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 13943
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
code:

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

Next

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 "application 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(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

Dim pnl As New Panel

pnl.Width = Me.Width

pnl.Anchor = AnchorStyles.Left Or AnchorStyles.Right Or
AnchorStyles.Top

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
form

pnl.BackColor = Color.PowderBlue

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.PowderBlue

ctl.Width = Me.Width

ctl.Height = Me.Height

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

ctl.Anchor = AnchorStyles.Left Or AnchorStyles.Bottom Or
AnchorStyles.Right Or AnchorStyles.Top

End If

Next

Me.BackColor = Color.PowderBlue

Dim frmChild As New Form 'now create a MDIchild form

frmChild.MdiParent = Me

frmChild.Show()

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
form.

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******@hotmail.com> wrote in message
news:wo9ce.4060$u56.933@trndny09...
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
closed.

(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.FullName <> "System.Windows.Forms.MdiClient" Then
obj.Visible = False
End If
Next obj
///

HTH
Nov 21 '05 #3

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

Similar topics

4
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...
9
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...
4
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...
3
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...
3
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...
1
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...
2
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...
4
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...
1
by: zEE | last post by:
How to close all the child windows when parent window get closed? in ASP.net application through scripting..
6
zybernau
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...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

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.