Solved

using MDIcontainer

Posted on 2006-10-31
8
173 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
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 17847566
Try deleting the "bin" subfolder in your project and running it again.
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

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…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.

863 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now