Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

using MDIcontainer

Posted on 2006-10-31
8
Medium Priority
?
186 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 86

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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 86

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 86

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 86

Accepted Solution

by:
Mike Tomlinson earned 80 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

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
Suggested Courses

810 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