How to Disable TEdit"s Default PopUp (Context) Menu

106 17


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;
Delphi tips navigator:
» How to Re-Initialize an Object to its Default State
« Programmatically Get and Set the State of the CapsLock and NumLock Keys

Source...
Subscribe to our newsletter
Sign up here to get the latest news, updates and special offers delivered directly to your inbox.
You can unsubscribe at any time

Leave A Reply

Your email address will not be published.