Results 1 to 8 of 8

Thread: Dont Show Form Twice..

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2002
    Location
    Canton, GA
    Posts
    487

    Dont Show Form Twice..

    Hey guys/gals I have a MDI form that will display and Inventory form if you select a button from the toolbar...

    Here is the problem...

    If you hit the button twice it will create a second form.. How can I stop that?

    Code:

    Case 1
    Dim NewMDIChild As New frmInventory()
    'Set the Parent Form of the Child window.
    NewMDIChild.MDIParent = Me
    'Display the new form.
    NewMDIChild.Show()
    Case 2
    etc etc etc

    Thanks in advance...

    Anjari
    Last edited by Anjari; Dec 18th, 2002 at 05:00 PM.

  2. #2
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    how many forms do you want to have?fixed numbers ??

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2002
    Location
    Canton, GA
    Posts
    487

    ...

    well i will have multiple forms.. Just not the same type..
    I guess what i could do is disable the button... but what I would like to do is keep it active and when pused the second time while the form is open bring that form to the front...


    Thanks,

    Anjari

  4. #4
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    You just have to store the instance that you make and then on other attempts check if it is Nothing. If it is nothing then make a new one otherwise just show the same instance.

  5. #5
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    VB Code:
    1. 'with form level scope
    2. Dim fInventory as frmInventory
    3.  
    4. 'in your code
    5. Case 1
    6.      If fInventory Is Nothing Then
    7.           fInventory=New frmInventory
    8.           fInventory.MDIParent = Me
    9.      End If
    10.      'Display the new form.
    11.      fInventory.Show()
    12. Case 2

  6. #6

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2002
    Location
    Canton, GA
    Posts
    487

    ok here is what i did....

    In a Module I put this:

    Public InventoryFormOpen As Boolean = False

    On my Main form Toolbar I put:

    Case 5
    If InventoryFormOpen = False Then
    Dim NewMDIChild As New frmInventory()
    'Set the Parent Form of the Child window.
    NewMDIChild.MDIParent = Me
    'Display the new form.
    NewMDIChild.Show()
    Else


    End If

    Then for my Inventory Form I placed:

    Private Sub frmInventory_Activated(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Activated
    InventoryFormOpen = True
    End Sub

    Private Sub frmInventory_Closed(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Closed
    InventoryFormOpen = False
    End Sub

    This has apparently kept my Form from showing twice... I am still new to VB and I am sure this is not the "proper way" but hey like I said it works...

    The only thing I need to figure out is to make that form the focus form it other forms are open and the toolbar button is pushed....

    thats why I have the "Else" area...

    Take Care,

    Anjari

  7. #7

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2002
    Location
    Canton, GA
    Posts
    487

    Sigh

    Now what happens:

    When you select a button on the toolbar it wont show the same form twice but if you select another button it WILL keep displaying that form over and over.... and vice versa....

    anyone out there that can help?


    Thanks,

    Anjari

  8. #8
    Registered User
    Join Date
    Nov 2002
    Location
    Växjö, Sweden
    Posts
    314
    There are various ways to deal with this I guess. I also wanted to show only one instance of each form at the most in one of my apps, but also if that button was hit I instead wanted to activate the form if there was one open in the background. So I did like this....

    Code:
    Dim frm As Form
    For Each frm In Me.MdiChildren
        If frm.GetType Is GetType(InventoryForm) Then
            frm.Activate()
            Exit Sub
        End If
    Next
    frm = New InventoryForm()
    With frm
        .MdiParent = Me
        .WindowState = FormWindowState.Maximized
        .Show()
    End With

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width