1. Computing & Technology

Discuss in my forum

How to Hide / Show the Main Menu of a Delphi Application

By , About.com Guide

The TMainMenu Delphi component encapsulates a menu bar and its accompanying drop-down menus for a form.

The TMainMenu Delphi component does not expose the Visible property to let you show or hide the menu for a form programmatically, does it? It does not, but there is a way to hide the main menu for a Delphi form at run time. Here's how...

To assign a menu for a form, drop a TMainMenu on it (let's say it has "MainMenu1" for its Name property), add menu items and asign it for the Menu property of a form.

If you want to hide the menu programmatically, at run-time, just use this line of code:

 //MainForm is the name of the form
 MainForm.Menu := nil;
 
To show the menu again, simply reassign the Menu property for the form:
 //MainForm is the name of the form
 MainForm.Menu := MainMenu1;
 
That's it.

Delphi tips navigator:
» PopupMenu With Different Item Heights (and Custom Graphics)
« How to Implement the OnCreate event for a Delphi TFrame object

©2012 About.com. All rights reserved.

A part of The New York Times Company.