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

页面导航:首页 > 软件编程 > Delphi > Delphi 学习日记:禁止TEdit或TMemo的“Ctrl+V”粘贴

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

来源: 作者: 时间:2016-01-21 09:33 【

今天去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 OnK...

今天去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.

 

摘自 金山野狼
Tags:

文章评论

最 近 更 新
热 点 排 行
Js与CSS工具
代码转换工具

<