Solved

MDI Childrens or Singleton

Posted on 2004-08-18
13
412 Views
Last Modified: 2006-11-17
Hello,
I have a vb.net application. But I only want to have 1 actife children.....
This is the issue.
I have a search option in my main menu, which works fine. However, if I select search again, it will open a new instance (child) instead of refreshing the previous one....
Please help
0
Comment
Question by:Ilianam
[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
  • 6
  • 3
  • 3
  • +1
13 Comments
 
LVL 15

Expert Comment

by:SRigney
ID: 11830935
You should be able to check to see if it already exists, and if it does switch to it instead of creating a new one each time.

In your main you can do something like this

Dim frmSearch As SearchForm

Then in your menu item click event

If frmSearch != null Then
   frmSearch.Show()
Else
   frmSearch = New SearchForm
End If

That should be close enough to give you the idea.
0
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 11830976
SRigney is right on track.  Here is a more complete example (assuming Form1 is the MDIParent and Form2 is the MDIChild):

Public Class Form1
    Inherits System.Windows.Forms.Form

    Private WithEvents f2 As Form2

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        If f2 Is Nothing Then
            f2 = New Form2
            f2.MdiParent = Me
            f2.Show()
        End If

        If f2.WindowState = FormWindowState.Minimized Then
            f2.WindowState = FormWindowState.Normal
        End If
        f2.Focus()
    End Sub

    Private Sub f2_Closed(ByVal sender As Object, ByVal e As System.EventArgs) Handles f2.Closed
        f2 = Nothing
    End Sub

End Class
0
 

Author Comment

by:Ilianam
ID: 11831638
Is this for vb.net?
0
Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

 

Author Comment

by:Ilianam
ID: 11831913
SGrigney It doesn't work
0
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 11832314
You can use this method:

    Private Function IsChildInMemory(ByVal pChildName As String) As Boolean
        'A small method that checks to see if a particular form is currently displayed as a child form
        Dim frmChild As Form
        For Each frmChild In Me.MdiChildren
            If TypeName(frmChild).ToUpper = pChildName.ToUpper Then
                frmChild.Activate()
                Return True
            End If
        Next
        Return False
    End Function
0
 

Author Comment

by:Ilianam
ID: 11833270
Emoreau,
It works, however if I "search" again its minimized...The main menu is an mdicontainer at run time....
0
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 11835529
>>however if I "search" again its minimized

What is minimizing your child form? You could check the windowstate to see if it is minimize!
0
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 11835665
Look at my example...it shows how to check the windowstate and put it back to normal...

Idle_Mind
0
 

Author Comment

by:Ilianam
ID: 11840951
Thank you...But I tried everything and I still cann't see my child.....
0
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 11841066
To further troubleshoot your problem we would need to see your code.

Idle_Mind
0
 
LVL 70

Accepted Solution

by:
Éric Moreau earned 500 total points
ID: 11841725
0
 

Author Comment

by:Ilianam
ID: 11841945
Thank you to all the solution was pretty simple
Private Sub MenuItem2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem2.Click
        If Me.MdiChildren.GetLength(0) < 2 Then
            Dim Look As New Search
            Look.MdiParent = Me
            Look.Text = "Search " & Me.MdiChildren.GetLength(0)
            Look.Show()
       end if
0
 

Author Comment

by:Ilianam
ID: 11841952
However is there a list of mdi properties that you can change at run time?
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

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

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

707 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