[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Layout MDI Child forms

Posted on 2009-04-13
5
Medium Priority
?
788 Views
Last Modified: 2012-05-06
Hi again,

Users are allowed to open multiple instances of a form.   Sometimes, although they may have other forms open, they will need to see just the two instances of one form side by side or up/down.
I would like to create a list that would display all forms that have multiple instances running and give them the option to layout just the selected form instances.
Any ideas?
Thanks
0
Comment
Question by:Sheritlw
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 10

Expert Comment

by:Jason Evans
ID: 24129114
Hi there.
I've written a quick and dirty routine that iterates through all the child forms of an MDI parent, keeping count of the number of time each form appears. So in my example, I had two child forms in the project - frm1 and frm2. Whilst running the code, I created 2 instances of frm1 and one instance of frm2.
When I ran GetFormCount() it found that there were two instances of frm1 and one of frm2.
Hope this helps.
Jas.

Private Sub GetFomCount()
        Dim formcount1 As Integer
        Dim formcount2 As Integer
 
        For Each frm As Form In MdiChildren
            If TypeOf frm Is frm1 Then
                formcount1 += 1
            End If
 
            If TypeOf frm Is frm2 Then
                formcount2 += 1
            End If
        Next
    End Sub

Open in new window

0
 
LVL 48

Expert Comment

by:jpaulino
ID: 24129652
It's like MrClyfar solution but a little more flexible. If you don't know how many forms you will have you don't know how many variables you will need.
I suggest you to use an HashTable and use the Keys for the form names and the Values for the total instances open. Something like this:


        Dim hash As New Hashtable
 
        ' Loops in all form childs
        For Each frm As Form In MdiChildren
 
            ' If the frm is not already in the table
            If Not hash.ContainsKey(frm.Name) Then
                hash.Add(frm.Name, 1)
            Else
                Dim total As Integer = hash.Item(frm.Name)
                hash.Item(frm.Name) = total + 1
            End If
 
        Next
 
 
        ' Shows the results
        For Each item As DictionaryEntry In hash
            If item.Value > 1 Then
                Debug.WriteLine(item.Key.ToString)
            End If
        Next

Open in new window

0
 

Author Comment

by:Sheritlw
ID: 24132120
The procedures listed for getting the forms are great, but how do I let them Tile Veritically/Horizontally just those two forms?
Thanks
0
 
LVL 86

Accepted Solution

by:
Mike Tomlinson earned 2000 total points
ID: 24309039
Here is a completely generic solution...

When the ToolStrip buttons are clicked (TileVertical, TileHorizontal), the ACTIVE MdiChild will be used to find all children of that same Type.  They will then be tiled evenly vertically or horizontally based on the button clicked.  So it would work with 2, 3, 4, or however many of that type you currently have open!

Example:
Public Class mdiParent
 
    Private Enum TileDirection
        Vertical
        Horizontal
    End Enum
 
    Private Sub TileVertical_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TileVertical.Click
        TileForms(TileDirection.Vertical)
    End Sub
 
    Private Sub TileHorizontal_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TileHorizontal.Click
        TileForms(TileDirection.Horizontal)
    End Sub
 
    Private Sub TileForms(ByVal direction As TileDirection)
        Dim frms As List(Of Form) = FindSimilarForms(Me.ActiveMdiChild)
        If frms.Count > 1 Then
            Dim mc As MdiClient = Me.Controls.OfType(Of MdiClient).First
            Dim sz As Integer = IIf(direction = TileDirection.Vertical, Math.Floor(mc.ClientSize.Width / frms.Count), Math.Floor(mc.ClientSize.Height / frms.Count))
            For i As Integer = 0 To frms.Count - 1
                Dim frm As Form = frms(i)
                If frm.WindowState <> FormWindowState.Normal Then
                    frm.WindowState = FormWindowState.Normal
                End If
                Select Case direction
                    Case TileDirection.Vertical
                        frm.SetBounds(i * sz, 0, sz, mc.ClientSize.Height)
 
                    Case TileDirection.Horizontal
                        frm.SetBounds(0, i * sz, mc.ClientSize.Width, sz)
 
                End Select
                frm.BringToFront()
            Next
        End If
    End Sub
 
    Private Function FindSimilarForms(ByVal child As Form) As List(Of Form)
        Dim matches As New List(Of Form)
        If Not IsNothing(child) Then
            For Each frm As Form In Me.MdiChildren
                If frm.GetType.Equals(child.GetType) Then
                    matches.Add(frm)
                End If
            Next
        End If
        Return matches
    End Function
 
End Class

Open in new window

0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …

649 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