Mega Code Archive

 
Categories / Delphi / VCL
 

How to Disable the Default PopUp (Context) Menu for a TEdit Delphi component

Title: How to Disable the Default PopUp (Context) Menu for a TEdit Delphi component When a user right-clicks on an Edit component at run time (or any other component that allows editing such as MaskEdit, Memo, DbEdit, etc.), by default the system's context menu pops up with options to undo, copy, paste, etc. One way to get rid of this default popup menu is to assign a "dummy" empty popup menu to the PopUpMenu property of a TWinControl descendant (TEdit, TMemo, etc.) Another way is to simply handle the OnContextPopup event by setting the Handled parameter to True. The OnContextPopup gets fired when the user right-clicks the control or otherwise invokes the popup menu (such as using the keyboard - pressing SHIFT+F10 or the Application key). Here's how the OnContextPopup implementation (to "disable" the context popup menu) looks like for the Edit1 (TEdit) component: procedure TForm1.Edit1ContextPopup( Sender: TObject; MousePos: TPoint; var Handled: Boolean) ; begin //disable default context popup Handled := True; end;