Главная страница | назад





Article #28457: How to disable a Menu item with out greying it out.

QUESTION:

How can I disable a Menu item, with out greying it out?

ANSWER:

There are times when you find that you want to disable an option while not greying it out completly. Drop a TMainMenu component on a Form and add atleast two menu items. Next drop a TButton on the Form and in the OnClick event, add the code show below. The code sample below demonstrates how to disable a Menu item without greying it out.


procedure TForm1.Button1Click(Sender: TObject);
var
Menu: TMenu;
begin
Menu := Application.MainForm.Menu;
// The first Menu item will be disabled, but not greyed out.
EnableMenuItem(Menu.Handle, Menu.Items[0].Command, MF_DISABLED);
end;

Last Modified: 05-MAR-02