Home All Groups Group Topic Archive Search About

disable/enable menu items

Author
26 Aug 2006 10:18 AM
John Devlon
Hi,
Can someone please help me. I've got a strang problem in Visual Studio
2005

I've created a windows application, using an MDI form and top menu.
When a menu item is clicked, a new instance of a form appeirs.


At the same time, i'm disabling the menu item to prevent opening it
again.


I've placed some code in the new form, so when it is closed, it should
re-enable the menu item in the main MDI-form.


Unfortunately, the menu-item will not re-enable.

The code I'm using in the main form for opening the new for and
disabling the menu item ...


        ViewMovieToolStripMenuItem.Enabled = False


        Dim objForm As dataform
        objForm = New dataform
        objForm.MdiParent = Me


        objForm.Show()


The code I'm using in the new form ...


    Private Sub dataform_FormClosed(ByVal sender As Object, ByVal e As
System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed


        frmMain.ViewMovieToolStripMenuItem.Enabled = True


    End Sub


Many thanx



john

Author
26 Aug 2006 6:55 PM
gene kelley
Show quote Hide quote
On Sat, 26 Aug 2006 10:18:32 GMT, "John Devlon" <johndev***@hotmail.com> wrote:

>Hi,
>Can someone please help me. I've got a strang problem in Visual Studio
>2005
>
>I've created a windows application, using an MDI form and top menu.
>When a menu item is clicked, a new instance of a form appeirs.
>
>
>At the same time, i'm disabling the menu item to prevent opening it
>again.
>
>
>I've placed some code in the new form, so when it is closed, it should
>re-enable the menu item in the main MDI-form.
>
>
>Unfortunately, the menu-item will not re-enable.
>
>The code I'm using in the main form for opening the new for and
>disabling the menu item ...
>
>
>        ViewMovieToolStripMenuItem.Enabled = False
>
>
>        Dim objForm As dataform
>        objForm = New dataform
>        objForm.MdiParent = Me
>
>
>        objForm.Show()
>
>
>The code I'm using in the new form ...
>
>
>    Private Sub dataform_FormClosed(ByVal sender As Object, ByVal e As
>System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed
>
>
>        frmMain.ViewMovieToolStripMenuItem.Enabled = True
>
>
>    End Sub
>
>
>Many thanx
>
>
>
>john
>

It looks like from what you posted, you may have more than one instance of objForm.

1) Channge:
     Dim objForm As dataform
    objForm = New dataform

to:
Dim objForm as New dataform


2) On the face of it, you used the FormClosed event in dataform, so one assumption here is that the
instance of the dataform is not visible, but not closed - FormClosed event not firing for other
reasons not shown in your posted code.
Try using the dataform_FormClosing event to enable the menu item.

Gene