程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 更多編程語言 >> Delphi >> Delphi 學習日記:禁止TEdit或TMemo的“Ctrl+V”粘貼

Delphi 學習日記:禁止TEdit或TMemo的“Ctrl+V”粘貼

編輯:Delphi

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

 

摘自 金山野狼

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved