需要拦截的有Ctrl+V和Shift+Insert,它们都是粘贴的快捷键procedure TForm1.RichEdit1KeyDown(Sender: TObject; var Key: Word; Shift: TShiftState); begin if ((Key = ord('V')) and (ssCtrl in Shift)) or ((Key = VK_INSERT) and (ssShift in Shift)) then Key := 0; end;
procedure TForm1.RichEdit1KeyDown(Sender: TObject; var Key: Word; Shift: TShiftState); begin if ((Key = ord('V')) and (ssCtrl in Shift)) or ((Key = VK_INSERT) and (ssShift in Shift)) then begin Key := 0; ShowMessage(Clipboard.AsText); end; end;
改写它们,就可以了
------------怎么拦截到Ctrl+V?
begin
if ((Key = ord('V')) and (ssCtrl in Shift))
or ((Key = VK_INSERT) and (ssShift in Shift)) then
Key := 0;
end;
begin
if ((Key = ord('V')) and (ssCtrl in Shift))
or ((Key = VK_INSERT) and (ssShift in Shift)) then
begin
Key := 0;
ShowMessage(Clipboard.AsText);
end;
end;
--------------------
uses ClipbrdShowMessage(ClipBoard.AsText);//获取剪贴板内容
ifClipboard.HasFormat(CF_TEXT) then //判断剪贴板内容是否为文本
ShowMessage(ClipBoard.AsText); //获取剪贴板内容
ShiftState := KeyDataToShiftState(Message.KeyData);
if(ssCtrl in ShiftState)and(Message.CharCode = 86)then
begin
lClipboard := TClipboard.Create;
lstrValue := lClipboard.AsText;
end;
lstrValue为剪贴板中的内容
1. 我前面就已经提到了Shift+Insert键的问题,并且给出的代码也处理了。2. Delphi中的RichEdit并不支持鼠标右键。