TechTricks
Technical answers from the trenches 
 
 
 
 

     
   
Hiding Default Shortcut Menus
 
   
 Posted: 12 June 2003
 
   
 
 Applies to: All versions
 
   
 
Audience: Beginner
 
       
   

Question: How to I prevent Delphi from displaying the default context (shortcut) menus that appear when you right-click certain objects by default?

Answer: Drop an empty TPopupMenu component on your form and then assign it to the PopupMenu property of the component with the default shortcut menu you want to hide.

To illustrate, let's assume you want to hide the default shortcut menu for a memo object. To do this:

  1. Create a new Delphi application.

  2. Place a TEdit, a TButton, and a TMemo on your default form.

  3. Run your application and then right-click the edit control and the memo object. Notice that each displays a default shortcut menu.

  4. Exit your application to return to the Delphi IDE.

  5. Place a TPopupMenu component on your form and name it pmBlankMenu.

  6. Select the memo object and then use the Object Inspector to assign pmBlankMenu to its PopupMenu property.

  7. Repeat Step 3 and notice that while a default shortcut menu appears when you right-click the edit control, nothing happens when you right-click the memo object.

Tips:

  1. To use this in more than one form, consider placing your empty popup menu in a data module and then sharing the data module between the forms of your application.

  2. To automatically disable default shortcut menus for a form's components, add the following code to your form's OnCreate event:

    procedure TForm1.FormCreate(Sender: TObject);
    var
       intCounter : Integer;
    begin
    
       for intCounter := 0 to ComponentCount - 1 do
          if components[ intCounter ] is tControl then
             with Components[ intCounter ] as tControl do
                if popupMenu = nil then
                   popupMenu := pmBlankMenu;
    
    end;

    This assigns pmBlankMenu to TControl descendants that don't already have shortcut menus. This works for TEdits, TMemos, and other controls descended from TControl, which surfaces the PopupMenu property.

There are, of course, different (and possibly more complicated) ways to do this. However, we feel this is the easiest--and fastest--to implement.

 

       

Top

Feedback About Paradox Delphi Assorted Web Stuff
 
 
Copyright © 2000-2004, techtricks.com; All Rights Reserved.
Acknowledgements, Disclaimers, Terms and Conditions.
Article last updated on 11 December 2003

 

Other Sites: Paradox, Delphi, Perl, Web Stuff, and More


 

[- End -]