在键盘按下事件中限制左右移动键、限制鼠标的抬起事件就可达到目地。
procedure TForm1.Edit1MouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
Edit1.SelLength := 0;
end;
procedure TForm1.Edit1KeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
if (Key = 37) or (Key = 39) then Key := 0;
end;
{
禁止Edit中选择内容
by 宋银海
QQ:25337012
}
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls,Clipbrd;
type
TForm1 = class(TForm)
Edit1: TEdit;
Button1: TButton;
procedure Edit1MouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
procedure Edit1KeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
private
{ Private declarations }
procedure NoSelect;
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Edit1KeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
begin //禁止键盘选择
NoSelect;
end;
procedure TForm1.Edit1MouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
begin//禁止鼠标选择
NoSelect;
end;
procedure TForm1.NoSelect;
begin//禁止选择
if Edit1.SelLength>0 then
begin
Edit1.SelStart:=0;
Edit1.SelLength:=0;
Edit1.SelText:='';
end;
end;
end.
既然能够可写,为什么不让复制啊,不符合需求吧,呵呵
是要不能选中还是不能复制啊?
两件事情呢