You are here:

C#/Algorithm for MdiLayout.TileVertical


Am writing a code to tile rectangles in a rectangular space.
Now I know .NET does a good job of tiling MDI child forms.
the MdiLayout.TileVertical is more suited for my purpose

Do u have an idea as to what Algorithm is used to tile the MDI Child Forms

Or is there a way to Tile Panels in similar fashion on a form.

Please Help
Thanking you

Hi there,

.Net uses SendMessage to tile child forms, using the way whole Windows does.
Here is the code:

public void LayoutMdi(MdiLayout value)
     if (this.Handle == IntPtr.Zero)
     switch (value)
       case MdiLayout.Cascade:
         this.SendMessage(551, 0, 0);
       case MdiLayout.TileHorizontal:
         this.SendMessage(550, 1, 0);
       case MdiLayout.TileVertical:
         this.SendMessage(550, 0, 0);
       case MdiLayout.ArrangeIcons:
         this.SendMessage(552, 0, 0);

That's why you have to write your own algorithm, which is not so complicated.
In my opinion this is the general algorithm to tile a rectangle vertically in parent rectangle.

1. Initialize integers iParentHeight=0, iChildHeight=0, iChildTop=0
2. iParentHeight = parent.Height
3. For each child in parent.Controls
4.   iChildHeight = iParentHeight / parent.Controls.Count
5.   child.Size = new Size(parent.Width, iHeight)
6.   child.Location = new Point(0, iChildTop)
7.   iChildTop += child.Width
8. Next
9. End

I wrote the algorithm using properties of Control class since you are looking for example of mdi forms. Now you can create the c# code and you may modify the algorithm to support margins as well.

If I misunderstood and directed you to the wrong point, feel free to ask again.

Hope that helps,



All Answers

Answers by Expert:

Ask Experts


Murat Mehmet


I can help with questions about desktop and web programming in C#, including SOAP, XML, database managing, custom controls, security etc.


I have been developing web and especially desktop applications in C# and VB.Net for almost 5 years. My programming life has begun with VB6 long time ago, so its about 8 years that I am in this business.

Was in R & D for 2 years in a popular Turkish technology website:

2011 Computer Engineering graduation in University of Trakia in Turkey.

©2017 All rights reserved.