How to Disabled or Enable a CloseMenustriptool

talahib098

New member
Joined
Oct 15, 2014
Messages
2
Programming Experience
Beginner
I got a system that I need the Close button in the parent form disabled where there is no active form and it is enabled if there is an active form. I use MDIcontainer.
any help guys...sorry if I'm a little beginner here.
 
E.g.
Public Class ParentForm

    Private Sub OpenButton_Click(sender As Object, e As EventArgs) Handles OpenButton.Click
        Dim child As New ChildForm

        AddHandler child.FormClosed, AddressOf ChildForm_FormClosed

        child.MdiParent = Me
        child.Show()
        Me.CloseButton.Enabled = True
    End Sub

    Private Sub CloseButton_Click(sender As Object, e As EventArgs) Handles CloseButton.Click
        Me.ActiveMdiChild.Close()
    End Sub

    Private Sub ChildForm_FormClosed(sender As Object, e As FormClosedEventArgs)
        Dim child = DirectCast(sender, ChildForm)

        RemoveHandler child.FormClosed, AddressOf ChildForm_FormClosed

        'If there is only one MDI child then the last one is being closed now so disable the Close button.
        Me.CloseButton.Enabled = (Me.MdiChildren.Count > 1)
    End Sub

End Class
 
didn't work...any other solution?
It does work. I tested it before I posted it and I tested it again just now. You obviously just did it wrong. If all you can manage is to post "didn't work" then I won't be making any more effort myself.
 
Back
Top