Delphi/Lazarus: Prevent user from using CTRL+C in Memo or Edit Field
Tutorial by Delphian | 2013-11-06 at 02:00
Sometimes you do not want that a user is able to copy texts from a TMemo or TEdit control to the clipboard. That is, if the user selects the text from an Edit field or some lines from a Memo and then presses CTRL and C on his keyboard, the text should not be copied to the clipboard.
With the following code in the OnKeyUp event of the Memo or the Edit, we can just do that:
uses ClipBrd; procedure Edit1KeyUp(Sender: TObject; var Key: Word; Shift: TShiftState); begin if (ssCtrl in Shift) and (Key = ord('C')) then begin Clipboard.AsText:=''; // or Clipboard.AsText:='DO NOT COPY FROM US!'; end; end;
The principle is as follows: First, we check which keys were pressed. If that is CTRL (Shift) and C (Key) at the same time, we set the clipboard content to an empty string. Thus, it is not possible for the user to copy a content to the clipboard.
Of course, instead of an empty string, we can also copy any other alternative text to the clipboard as the uncommented line shows.
About the Author
The author has not added a profile short description yet.
Show Profile
Related Topics
How to Replace multiple Texts at the same Time
Tutorial | 0 Comments
Delphi/Lazarus: Catch CTRL+C in Memo or Edit and Change Clipboard Content
Tutorial | 0 Comments
Remove Spaces from the Beginning and End of the Lines of Texts
Tutorial | 0 Comments
Delphi/Lazarus: Only allow Numbers in TEdit
Tip | 0 Comments
Firefox: 15 useful keyboard shortcuts no one knows
Article | 0 Comments
Delphi/Lazarus: Is the ALT, SHIFT or CTRL key pressed?
Tutorial | 0 Comments
Delphi: CanvasTextOut: Align Left, Right and Center
Tip | 0 Comments
Important Note
Please note: The contributions published on askingbox.com are contributions of users and should not substitute professional advice. They are not verified by independents and do not necessarily reflect the opinion of askingbox.com. Learn more.
Participate
Ask your own question or write your own article on askingbox.com. That’s how it’s done.