Solved

using MDIcontainer

Posted on 2006-10-31
8
174 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
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 
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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

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…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
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 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…

785 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