灯火互联
管理员
管理员
  • 注册日期2011-07-27
  • 发帖数41778
  • QQ
  • 火币41290枚
  • 粉丝1086
  • 关注100
  • 终身成就奖
  • 最爱沙发
  • 忠实会员
  • 灌水天才奖
  • 贴图大师奖
  • 原创先锋奖
  • 特殊贡献奖
  • 宣传大使奖
  • 优秀斑竹奖
  • 社区明星
阅读:3004回复:0

Delphi 学习日记:禁止TEdit或TMemo的“Ctrl+V”粘贴

楼主#
更多 发布于:2012-09-08 13:04


今天去About.com逛了逛,学到一点东西,记下来
No "Paste" for you!
To intercept any key combination for a TEdit (or TMemo or more generally TCustomEdit) you need to handle the OnKeyDown event.
Put a TEdit named "Edit1" on a form (named "Form1"). Handle Edit1's OnKeyDown event as:
uses Clipbrd, ...

//disable CTRL + V ("Paste") :: handles Edit1.OnKeyDown
procedure TForm1.Edit1KeyDown(Sender: TObject; var Key: word; Shift: TShiftState) ;
begin
   if ((ssCtrl in Shift) AND (Key = ord('V'))) then
   begin
     if Clipboard.HasFormat(CF_TEXT) then ClipBoard.Clear;

     Edit1.SelText := '"Paste" DISABLED!';

     Key := 0;
   end;
end;
When the user presses the CTRL+V key combination while Edit1 has the input focus ... the code above will clear the clipboard and "paste" the '"Paste" DISABLED!' text into the edit control.


喜欢0 评分0
游客

返回顶部