Home All Groups Group Topic Archive Search About

How to restrict the multiple opening of the Same window...

Author
12 Feb 2005 12:31 AM
Prabhudhas Peter
If I click a menu to open a form which already open...the vb.net opens a new
window while existing open window is there...i want to restric the opening of
a new instance of an already opened form...
and also ...
if i open a form from a child form of an MDI form, the recently opened form
also should be the child of that MDI form...
--
Peter...

Author
12 Feb 2005 12:50 AM
Herfried K. Wagner [MVP]
"Prabhudhas Peter" <PrabhudhasPe***@discussions.microsoft.com> schrieb:
> If I click a menu to open a form which already open...the vb.net opens a
> new
> window while existing open window is there...i want to restric the opening
> of
> a new instance of an already opened form...
> and also ...

\\\
Private m_Child As Form2

Private Sub Button1_Click( _
    ByVal sender As Object, _
    ByVal e As EventArgs _
) Handles Button1.Click
    If m_Child Is Nothing Then
        m_Child = New Form2()
        m_Child .MdiParent = Me
        AddHandler m_Child.Load, AddressOf Me.MdiChild_Load
        AddHandler m_Child.Closed, AddressOf Me.MdiChild_Closed
    End If
    m_Child.Show()    ' ...
End Sub

Private Sub MdiChild_Load( _
    ByVal sender As Object, _
    ByVal e As EventArgs _
)
    MsgBox( _
        "MDI child with handle " & _
        DirectCast(sender, Form).Handle.ToString() & _
        " loaded!" _
    )
End Sub

Private Sub MdiChild_Closed( _
    ByVal sender As Object, _
    ByVal e As EventArgs _
)
    MsgBox( _
        "MDI child with handle " & _
        DirectCast(sender, Form).Handle.ToString() & _
        " closed!" _
    )
    m_Child = Nothing
End Sub
///

Alternatively you can implement the Singleton design pattern in your MDI
child form:

Implementing the Singleton Pattern in C#
<URL:http://www.yoda.arachsys.com/csharp/singleton.html>

Exploring the Singleton Design Pattern
<URL:http://msdn.microsoft.com/library/en-us/dnbda/html/singletondespatt.asp>

Design Pattern: Singleton in C#
<URL:http://www.devhood.com/tutorials/tutorial_details.aspx?tutorial_id=486>

Design Patterns: Singleton
<URL:http://www.dofactory.com/Patterns/PatternSingleton.aspx>

> if i open a form from a child form of an MDI form, the recently opened
> form
> also should be the child of that MDI form...

\\\
Dim f As New FooForm()
f.MdiParent = Me.MdiParent
f.Show()
///

--
M S   Herfried K. Wagner
M V P  <URL:http://dotnet.mvps.org/>
V B   <URL:http://dotnet.mvps.org/dotnet/faqs/>
Author
30 Mar 2005 1:51 PM
Woo
ur coding works great. but what if i hv different forms for different usage?
i need to repeat the load and close to indicate those forms = nothing? maybe
you could advise on that. thanks a lot.

Show quoteHide quote
"Herfried K. Wagner [MVP]" wrote:

> "Prabhudhas Peter" <PrabhudhasPe***@discussions.microsoft.com> schrieb:
> > If I click a menu to open a form which already open...the vb.net opens a
> > new
> > window while existing open window is there...i want to restric the opening
> > of
> > a new instance of an already opened form...
> > and also ...
>
> \\\
> Private m_Child As Form2
>
> Private Sub Button1_Click( _
>     ByVal sender As Object, _
>     ByVal e As EventArgs _
> ) Handles Button1.Click
>     If m_Child Is Nothing Then
>         m_Child = New Form2()
>         m_Child .MdiParent = Me
>         AddHandler m_Child.Load, AddressOf Me.MdiChild_Load
>         AddHandler m_Child.Closed, AddressOf Me.MdiChild_Closed
>     End If
>     m_Child.Show()    ' ...
> End Sub
>
> Private Sub MdiChild_Load( _
>     ByVal sender As Object, _
>     ByVal e As EventArgs _
> )
>     MsgBox( _
>         "MDI child with handle " & _
>         DirectCast(sender, Form).Handle.ToString() & _
>         " loaded!" _
>     )
> End Sub
>
> Private Sub MdiChild_Closed( _
>     ByVal sender As Object, _
>     ByVal e As EventArgs _
> )
>     MsgBox( _
>         "MDI child with handle " & _
>         DirectCast(sender, Form).Handle.ToString() & _
>         " closed!" _
>     )
>     m_Child = Nothing
> End Sub
> ///
>
> Alternatively you can implement the Singleton design pattern in your MDI
> child form:
>
> Implementing the Singleton Pattern in C#
> <URL:http://www.yoda.arachsys.com/csharp/singleton.html>
>
> Exploring the Singleton Design Pattern
> <URL:http://msdn.microsoft.com/library/en-us/dnbda/html/singletondespatt.asp>
>
> Design Pattern: Singleton in C#
> <URL:http://www.devhood.com/tutorials/tutorial_details.aspx?tutorial_id=486>
>
> Design Patterns: Singleton
> <URL:http://www.dofactory.com/Patterns/PatternSingleton.aspx>
>
> > if i open a form from a child form of an MDI form, the recently opened
> > form
> > also should be the child of that MDI form...
>
> \\\
> Dim f As New FooForm()
> f.MdiParent = Me.MdiParent
> f.Show()
> ///
>
> --
>  M S   Herfried K. Wagner
> M V P  <URL:http://dotnet.mvps.org/>
>  V B   <URL:http://dotnet.mvps.org/dotnet/faqs/>
>
>