如何拦截(检测)粘贴命令到TMemo? [英] How to intercept (detect) a Paste command into a TMemo?
问题描述
如何抓住粘贴命令和更改剪贴板的文本,然后将该文本粘贴到TMemo中,但粘贴后,剪贴板中的文本必须与更改前一样?
How to catch Paste command and change text of Clipboard before that text is pasted into a TMemo, but, after Paste, text in Clipboard must be same like before changing?
示例,剪贴板有文本简单问题,TMemo中的文本是СимплeQуeстиoн,之后剪贴板中的文本就像更改之前的简单问题一样。
Example, Clipboard have text 'Simple Question', text that go in the TMemo is 'Симплe Qуeстиoн', and after that text in Clipboard is like before changing, 'Simple Question'.
推荐答案
导出从TMemo下降的新控件拦截 WM_PASTE
message:
Derive a new control that descends from 'TMemo' to intercept the WM_PASTE
message:
type
TPastelessMemo = class(TMemo)
protected
procedure WMPaste(var Message: TWMPaste); message WM_PASTE;
end;
uses
clipbrd;
procedure TPastelessMemo.WMPaste(var Message: TWMPaste);
var
SaveClipboard: string;
begin
SaveClipboard := Clipboard.AsText;
Clipboard.AsText := 'Simple Question';
inherited;
Clipboard.AsText := SaveClipboard;
end;
如果您想禁止任何粘贴操作,请清空WMPaste处理程序。
If you would like to prohibit any paste operation at all, empty the WMPaste handler.
这篇关于如何拦截(检测)粘贴命令到TMemo?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!