我没有使用控件,楼主觉得有必要,可以从TCustomEdit重新继承一个,以下测试代码给你了,楼主也可以从以下地址下载:
地址: ftp.mlfjnp.com
帐户和密码均为:dfw
unit frmMain;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Edit1: TEdit;
Button1: TButton;
Label1: TLabel;
OverriteBtn: TButton;
procedure FormCreate(Sender: TObject);
procedure OverriteBtnClick(Sender: TObject);
procedure Edit1KeyPress(Sender: TObject; var Key: Char);
private
{ Private declarations }
public
{ Public declarations }
OverriteFlag:boolean;
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
begin
OverriteFlag:=False;
end;
procedure TForm1.OverriteBtnClick(Sender: TObject);
begin
OverriteFlag:=not OverriteFlag;
if OverriteFlag then OverriteBtn.Caption:='改写'
else OverriteBtn.Caption:='插入';
end;
procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);
var tt:TPoint;
begin
if Key in ['0'..'9','a'..'z','A'..'Z'] then //在此可以加入一些判断,感觉输入汉字时,会有一点问题
if OverriteFlag then
begin
keybd_event(VK_DELETE, MapVirtualkey(VK_DELETE, 0),
KEYEVENTF_EXTENDEDKEY, 0);
keybd_event(VK_DELETE, MapVirtualkey(VK_DELETE, 0),
KEYEVENTF_EXTENDEDKEY or KEYEVENTF_KEYUP, 0);
end;
GetCaretPos(tt);
Label1.Caption:='x='+IntToStr(tt.X)+',y='+IntToStr(tt.y);
end;
end.