?
Solved

How to create a Custom MDI Layout in .NET

Posted on 2009-02-19
3
Medium Priority
?
529 Views
Last Modified: 2013-12-17
I have an MDI application with the Windows Menu.  The current MDILayouts are ArrangeIcons, Cascade, TileHorizontal, and TileVertical.  I set this using the LayoutMDI command.  Is there a way to expand that to get say a "Tile Quad" option where four windows are tiled in a quad mode?

I would also something similar to this question, however I don't want it automatic, I would like to call this behavior from the Windows Menu
http://www.experts-exchange.com/Programming/System/Windows__Programming/MFC/Q_10235659.html?sfQueryTermInfo=1+custom+mdi+tile

However I would like the solution for .NET, preferably VB.NET
0
Comment
Question by:tedunni
  • 2
3 Comments
 
LVL 86

Accepted Solution

by:
Mike Tomlinson earned 1000 total points
ID: 23687395
It might look something like this:
Public Class YourMdiParentFormNameHere
 
    Private Sub TileQuadToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TileQuadToolStripMenuItem.Click
        If Me.MdiChildren.Count = 4 Then
            For Each child As Form In Me.MdiChildren
                child.WindowState = FormWindowState.Normal
            Next
 
            Dim mc As MdiClient = Nothing
            For Each ctl As Control In Me.Controls
                If TypeOf ctl Is MdiClient Then
                    mc = ctl
                    Dim w As Integer = mc.ClientSize.Width / 2
                    Dim h As Integer = mc.ClientSize.Height / 2
                    Me.MdiChildren(0).SetBounds(0, 0, w, h)
                    Me.MdiChildren(1).SetBounds(w, 0, w, h)
                    Me.MdiChildren(2).SetBounds(0, h, w, h)
                    Me.MdiChildren(3).SetBounds(w, h, w, h)
                    Exit For
                End If
            Next
        End If
    End Sub
 
End Class

Open in new window

0
 

Author Comment

by:tedunni
ID: 23688515
I had to change
If Me.MdiChildren.Count = 4 Then
to
If Me.MdiChildren.Length = 4 Then

but everything else worked great.  Thanks.  Btw, what I ended up using in order to somewhat match what was done in the link is below:



Public Class YourMdiParentFormNameHere
    Private Sub TileQuadToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TileQuadToolStripMenuItem.Click
 
    Dim mc As MdiClient = Nothing
    For Each ctl As Control In Me.Controls
      If TypeOf ctl Is MdiClient Then
        mc = ctl
        Dim w As Integer = mc.ClientSize.Width / 2
        Dim h As Integer = mc.ClientSize.Height / 2
        Select Case Me.MdiChildren.Length
          Case 1
            Me.MdiChildren(0).WindowState = FormWindowState.Maximized
          Case 2
            Me.MdiChildren(0).SetBounds(0, 0, w * 2, h)
            Me.MdiChildren(1).SetBounds(0, h, w * 2, h)
            Exit For
          Case 3
            Me.MdiChildren(0).SetBounds(0, 0, w * 2, h)
            Me.MdiChildren(1).SetBounds(0, h, w, h)
            Me.MdiChildren(2).SetBounds(w, h, w, h)
            Exit For
          Case 4
            Me.MdiChildren(0).SetBounds(0, 0, w, h)
            Me.MdiChildren(1).SetBounds(w, 0, w, h)
            Me.MdiChildren(2).SetBounds(0, h, w, h)
            Me.MdiChildren(3).SetBounds(w, h, w, h)
          Case Else
            Me.MdiChildren(0).SetBounds(0, 0, w, h)
            Me.MdiChildren(1).SetBounds(w, 0, w, h)
            Me.MdiChildren(2).SetBounds(0, h, w, h)
            Me.MdiChildren(3).SetBounds(w, h, w, h)
        End Select
        Exit For
      End If
    Next
  End Sub
End Class

Open in new window

0
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 23688786
Glad I was able to help...I know the code I posted wasn't very robust but it was a good starting point.  =)
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
Integration Management Part 2
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses

571 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question