Disable the one item in Menu Bar

  • Thread starter Thread starter Agnes
  • Start date Start date
A

Agnes

In my menu, there is invoice,customer .... etc
As the user click 'Invoice' , the invoice form is load, then I want to
disable the "Invoice" menu in the Menuitem, ,so the user can only new one
invoice form and the user can new another form like 'delivery order'.. etc.
In such case, I won't use' showdialog'.
Thanks a lot
From AGnes
 
I need to explain more about my purpose, In fact I know how to disable the
menu.
But , as the user close that invoice form, "the menu should be set to
enabled = true"
How can I do that ??
Thanks
 
mi.Enabled = False


--

OHM ( Terry Burns )
. . . One-Handed-Man . . .

Time flies when you don't know what you're doing
 
* "Agnes said:
In my menu, there is invoice,customer .... etc
As the user click 'Invoice' , the invoice form is load, then I want to
disable the "Invoice" menu in the Menuitem, ,so the user can only new one
invoice form and the user can new another form like 'delivery order'.. etc.
In such case, I won't use' showdialog'.

In the menu item's 'Click' event handler:

\\\
DirectCast(sender, MenuItem).Enabled = False
///
 
\\\
Private WithEvents MyInvoiceForm As Form

Sub InvoiceMenu_Click(...)...
InvoiceMenu.Enabled = False
MyInvoiceForm = New InvoiceForm
MyInvoiceForm.Owner = Me
MyInvoiceForm .Show
End Sub

Sub MyInvoiceForm _Closed(...)...
InvoiceMenu.Enabled = True
End Sub
///
 
Here are three approaches, in increasing order of preference:

1. For the invoice form, code a new constructor that takes a form as an
argument. When you create the invoice form with that constructor, pass
'this' as the argument to the constructor. In the invoice's Closing event,
it can find and enable the menu item on the form that holds the menu. This
is not so good, because it requires the invoice form to know a lot about the
logic of the form it was invoked from.

2. Same as (1), except that the invoice form, instead of finding and
enabling the menu item, calls some method on the form that holds the menu.
This method, which you create, finds and modifies the menu item. This
approach is sometimes called a 'secondary interface'. It is better than (1),
because it does not require the invoice form to know anything about how it
was invoked, but it couples the logic of the two forms pretty closely.

3. On the invoice form, create an event that the form's Closing event would
raise during its shutdown process. In the form that has the menu, wire up an
event handler to that event, and do all the menu item manipulation in that
event. This approach would be my preference, mainly because it uses an
established mechanism that's loosely-coupled.

Hope this helps,
Tom Dacon
Dacon Software Consulting
 
Back
Top