Solved

using MDIcontainer

Posted on 2006-10-31
8
172 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Try deleting the "bin" subfolder in your project and running it again.
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

Author Comment

by:kengkit
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
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…
This video discusses moving either the default database or any database to a new volume.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

762 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

10 Experts available now in Live!

Get 1:1 Help Now