Solved

using MDIcontainer

Posted on 2006-10-31
8
175 Views
Last Modified: 2010-04-23
hellow guys.. i got a form named "form_master" which "IsMdiContainer" = True

the following code is the way how i open another form in "form_master"
my question is: How do i prevent duplicated "form_sales" being open?

----------------------------------------------------------------------------------------------------
Public Class form_master

    Dim sales_form As form_sales

    Private Sub button_1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btn_POS.Click

        sales_form = New form_sales()
        sales_form.MdiParent = Me
        sales_form.Show()

    End Sub

End Class
0
Comment
Question by:kengkit
  • 4
  • 4
8 Comments
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 17845231
Something like...

Public Class form_master

    Private WithEvents sales_form As New form_sales

    Private Sub button_1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btn_POS.Click
        If sales_form Is Nothing Then
            sales_form = New form_sales()
            sales_form.MdiParent = Me
            sales_form.Show()
        End If
        If sales_form.WindowState = FormWindowState.Minimized Then
            sales_form.WindowState = FormWindowState.Normal
        End If
        sales_form.Activate()
    End Sub

    Private Sub sales_form_FormClosed(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Handles sales_form.FormClosed
        sales_form = Nothing
    End Sub

End Class
0
 

Author Comment

by:kengkit
ID: 17847137
To: Idle_Mind

how come i still can open duplicated form althought i used your code exactly?

The application doen't stop even I put the breakpoint at "If sales_form Is Nothing"
why?? (I was using visual studio .net 2005

Private Sub button_1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btn_POS.Click

        If sales_form Is Nothing Then  (breakpoint)
            sales_form = New form_sales()
            sales_form.MdiParent = Me
            sales_form.Show()
        End If

        If sales_form.WindowState = FormWindowState.Minimized Then
            sales_form.WindowState = FormWindowState.Normal
        End If

        sales_form.Activate()

    End Sub
0
 

Author Comment

by:kengkit
ID: 17847159
I found tat my application doesn't recognize my changed code...

For an instance..

Private Sub Button5_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button5.Click

    MsgBox("Hellow")

End Sub

The message box doesn't pop up when i click button5
0
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.

 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 17847566
Try deleting the "bin" subfolder in your project and running it again.
0
 

Author Comment

by:kengkit
ID: 17847579
all right.. now the problem is..

sales_form doesn't pop up.... unless i changed the code

from "If sales_form Is Nothing Then" to "If sales_form Is Nothing = False Then"

----------------------------------------------------------------------------------------------

Public Class form_master

    Private WithEvents sales_form As New form_sales

    Private Sub sales_form_FormClosed(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Handles sales_form.FormClosed
        sales_form = Nothing
    End Sub

    Private Sub ToolStripButton1_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton1.Click

        If sales_form Is Nothing = False Then
            sales_form = New form_sales()
            sales_form.MdiParent = Me
            sales_form.Show()
        End If

        If sales_form.WindowState = FormWindowState.Minimized Then
            sales_form.WindowState = FormWindowState.Normal
        End If

        sales_form.Activate()
    End Sub

End Class
0
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 17847595
You're using VB.Net 2005 right?

Try:

        If IsNothing(sales_form) Then
            sales_form = New form_sales()
            sales_form.MdiParent = Me
            sales_form.Show()
        End If
0
 

Author Comment

by:kengkit
ID: 17847602
Yup.. i'm using VS.net 2005 (VB)

i tried ur code oledi.. but the problem is existed
0
 
LVL 85

Accepted Solution

by:
Mike Tomlinson earned 20 total points
ID: 17847734
Sorry...

Public Class form_master

    Private WithEvents sales_form As form_sales          '<------- removed the "new"

    Private Sub sales_form_FormClosed(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Handles sales_form.FormClosed
        sales_form = Nothing
    End Sub

    Private Sub ToolStripButton1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton1.Click
        If IsNothing(sales_form) Then
            sales_form = New form_sales()
            sales_form.MdiParent = Me
            sales_form.Show()
        ElseIf sales_form.WindowState = FormWindowState.Minimized Then
            sales_form.WindowState = FormWindowState.Normal
        End If
        sales_form.Activate()
    End Sub

End Class
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone 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

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

831 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