对于TEdit组件,组件是否可以通过将换行符转换为空格来处理来自Windows剪贴板的多行粘贴?
换句话说,如果Windows剪贴板上有以下数据:
Hello
world
!
...并且用户将光标放在TEdit中然后按下CTRL + V,是否可以让TEdit显示输入为:
Hello world!
答案 0 :(得分:12)
您需要使用插入器类对TEdit
进行子类化,并为WM_PASTE
消息添加处理程序:
unit Unit3;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, DB, adsdata, adsfunc, adstable;
type
TEdit= class(StdCtrls.TEdit)
procedure WMPaste(var Msg: TWMPaste); message WM_PASTE;
end;
type
TForm3 = class(TForm)
AdsTable1: TAdsTable;
Edit1: TEdit;
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form3: TForm3;
implementation
{$R *.dfm}
uses
Clipbrd;
{ TEdit }
procedure TEdit.WMPaste(var Msg: TWMPaste);
var
TempTxt: string;
begin
TempTxt := Clipboard.AsText;
TempTxt := StringReplace(TempTxt, #13#10, #32, [rfReplaceAll]);
Text := TempTxt;
end;
end.