Open Child Window ONCE

Hi,

I created a Parent form and a main menu, where user can select and click a menu item and Show a child MDI form. I'm able to add a "tick" beside this menu item on the main menu, but how can I "disable" this menu item so that user can NOT click on this menu item AGAIN and open n x this child form  



Answer this question

Open Child Window ONCE

  • Annuzzer

    Have not figured that out yet.

    Matt

  • rkvajrala

    Here is the way I was able to stop opening child window more then once.


    Create a Function:
        Private Function CheckIfOpen(ByVal frmName As String) As Boolean
            Dim frm As Form
            For Each frm In Me.MdiChildren
                If frm.Name = frmName Then
                    frm.Focus()
                    Return true
                    Exit Function
                End If
            Next
            Return False
        End Function

    add code to where you open the form. (menu or button)

    If CheckIfOpen("frmVoidPrintedCoupons")=False Then
                Dim fv As New frmVoidPrintedCoupons
                fv.MdiParent = Me
                fv.Show()
            End If

    Pass the name of the child window to the function. Loop through each mdichild. If found then set forcus to the one that is open else return true and open the window for the first time.


    There might be a better way to do this, If so please let me know. 

    Matt

  • MichaelP_Oxy

    http://www.windowsforms.com/Forums/ShowPost.aspx tabIndex=1&tabId=41&PostID=13066

    I put up a set of overloads I use.

    basiclly same as above, but I pass in type rather than name, and a few other parameters in the overloads to call specific commands such as focus and close.

  • nothingbutdotnet

    Yeah, Thanks Matt, I did something similar to yours recently, and the main idea is to loop through all the menu item and compare with the active one, and then "check" the active one.

    However, another problem come out: How do I "enable" the menu item after I close the child form  I mean, I can limit the child form to pop up once, but how do I "activate" the menu item after the ChildForm_Closed 

    Thanks

  • vb_sagacious

    I do it a bit differently

    First I declare 

     Private ActiveOpenForm As Form


    Then in the procedure 
        dim bIsActive as boolean=false
                    For Each frm In Me.MdiChildren
                        If frm Is ActiveDocForm Then
                            'make it the active form
                          bIsActive = true
                          exit for
                        End If
                    next

    if  bIsActive = false

    then open a new one


  • WinFXGuy

    Another way to achieve this, is to make use of the singleton design pattern for your ChildForm class
  • Pin

    Try this.  What you want is a Singleton Pattern.


    Windows Forms FAQ

    32.4 How do I check to see if a child form is already displayed so I don't have two instances showing

    http://www.syncfusion.com/FAQ/WinForms/FAQ_c4c.asp#q521q

  • _StevenB_



    override the child_form's onclose event.

    Have it access the parent_form via me.mdiparent (vb.net) from this, you can access any friend function/sub/property/etc by typing this generic form object, to the same class as your parent form.  Then after the mdiparent is typed to your parent_form type, just call the sub that does the "enabling" of the menu.

     (vb.net ex:  ctype(me.mdiparent, frmMain).subToEnableMenus   )


  • Open Child Window ONCE