?
Solved

MDI - Prevent Reuse Child windows or Prevent Multiple instances of a child window.

Posted on 2004-09-08
12
Medium Priority
?
465 Views
Last Modified: 2008-01-16
Basically what I am trying to do is reuse my child windows.
Take a look at the Outlook 2003 interface, and I'm basically trying to mimic this using MDI.

If the MDI Child is already open, I would like to just display the current one instead of opening another.

How is this possible?
I'm in a pinch for time, so big points for this one!
Thanks
0
Comment
Question by:acheaney
[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
12 Comments
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 12008216
Here is one way:

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        If Not loadMDIChild("Form2") Then
            Dim f As New Form2
            f.Name = "Form2"
            f.MdiParent = Me
            f.Show()
        End If
    End Sub

    Private Function loadMDIChild(ByVal childName As String) As Boolean
        Dim f As Form
        For Each f In Me.MdiChildren
            If f.Name.Equals(childName) Then
                If f.WindowState = FormWindowState.Minimized Then
                    f.WindowState = FormWindowState.Normal
                End If
                f.Focus()
                Return True
            End If
        Next
        Return False
    End Function
0
 

Expert Comment

by:Ilianam
ID: 12018198
I make a class like this

Public Class clsGlobals
    'I make a class with Public Shared variables with the type as the Form itself.
#Region "Singleton Forms"
    Public Shared gfrmSearch As frmSearch
    Public Shared gfrmContact As frmContact
#End Region
 
Then  from my menu:
Private Sub MenuItem1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem1.Click

        'to open the form I use the following...
        'I use the focus to ensure it is always in the foreground
        'this can be important in MDI application
        'this is also what enforces singleton
        If clsGlobals.gfrmSearch Is Nothing Then
            clsGlobals.gfrmSearch = New frmSearch
        End If

        clsGlobals.gfrmSearch.MdiParent = Me
        'if it isn't nothing then the Show() method will still bring it up
        clsGlobals.gfrmSearch.Show()
        clsGlobals.gfrmSearch.Focus()

    End Sub
End Class
and in each form
End Class

Then
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        'to open the form I use the following...
        'I use the focus to ensure it is always in the foreground
        'this can be important in MDI application
        'this is also what enforces singleton
        If clsGlobals.gfrmContact Is Nothing Then
            clsGlobals.gfrmContact = New frmContact
        End If

        clsGlobals.gfrmContact.MdiParent = Me.MdiParent

        'if it isn't nothing then the Show() method will still bring it up
        clsGlobals.gfrmContact.Show()
        clsGlobals.gfrmContact.Focus()
    End Sub

IMPORTANT

   clsGlobals.gfrmSearch = Nothing 'set the variable to nothing for future searches if window is closed.
0
 

Author Comment

by:acheaney
ID: 12035596
With either of these, as I switch between windows, the sizes of them keep changing.
All the windows should stay maximized, but they keep changing.

They also flicker the previously opened windows before changing.
Can this be hidden?
0
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.

 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 12035716
Interesting behaviour...

When the child windows are maximized and you switch to another child window, the current child windowstate is reset to normal before the child being switched to is brought up.

Still tyring to find a solution to the problem...

Idle_Mind
0
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 12035725
Lol...the problem appears to be in the way the OS handles MDI children.
http://www.experts-exchange.com/Programming/Programming_Languages/Delphi/Q_10072028.html
0
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 12035806
I am finding many, many posts here on EE dealing with this exact problem in several of the TAs.  The language doesn't seem to matter as this problem is a result of the way windows deals with MDI children.  The dates of these questions go all the way back to the earliest days of EE in the late 90's.

Most of the solutions solve the problem by not using borders on the children forms.  Some make the normal size of the form the same as the maximized size no matter what.

I couldn't find one solution that REALLY solved the problem elegantly though.

I'm thinking it would be possible to subclass the form whenever it is maximized and change the MINMAXINFO so that the minimum size is always the same as the maximized size.  Still trying to figure out how to determine when the form should be restored back to a normal state though.

Working on it...

Idle_Mind
0
 
LVL 86

Accepted Solution

by:
Mike Tomlinson earned 1000 total points
ID: 12036007
I think the problem is that when you switch windows, a WM_MDIACTIVATE message is sent to both the window losing focus and the window receiving focus:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/WinUI/WindowsUserInterface/Windowing/MultipleDocumentInterface/MultipleDocumentInterfaceReference/MultipleDocumentInterfaceMessages/WM_MDIACTIVATE.asp

Again, I think the only way to really solve the problem is subclassing the MDI child and/or MDI parent to either change or consume the MDI messages or the WM_SIZING message.

At any rate, it will be messy.

Idle_Mind
0
 

Expert Comment

by:Ilianam
ID: 12036009
Helllo,
But the whole idea of the very impotant part is that you copy that in the dispose event for every form.
In my example I only want to have ONE CHIld, like I select a form1, and that one opens form2, if I make changes In form2 and need to go back to form1 I will have the same results because this child exist
0
 
LVL 8

Assisted Solution

by:wguerram
wguerram earned 1000 total points
ID: 12044298
Check this:

http://www.experts-exchange.com/Programming/Programming_Languages/Dot_Net/VB_DOT_NET/Q_21098926.html

The accepted answer checks if the form is already open, if so just activate it.
0

Featured Post

[Webinar] How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them.

Question has a verified solution.

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

A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses
Course of the Month8 days, 22 hours left to enroll

764 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