鼠标划线时,怎样使一虚线跟随鼠标移动,在鼠标松开时真正划一实线。(0分)

  • 主题发起人 主题发起人 轩轩
  • 开始时间 开始时间

轩轩

Unregistered / Unconfirmed
GUEST, unregistred user!
鼠标划线时,怎样使一虚线跟随鼠标移动,在鼠标松开时真正划一实线。
 
你的机子里面有例子呀,快去看看吧!
C:/Program Files/Borland/Delphi5/Demos/Doc/Graphex/Graphex.dpr
 
var
Form1: TForm1;
First, Mdown: Boolean;
ox, oy, ox1, oy1: Integer;
implementation

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
begin
Mdown := false;
Canvas.Pen.Mode := pmNotXor;
Canvas.Pen.Color := clblack;
Canvas.Pen.Style :=psDot;
end;

procedure TForm1.FormMouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
begin
if Mdown then
begin
if not First then
begin
Canvas.moveto(ox, oy);
Canvas.LineTo(ox1, oy);
Canvas.moveto(ox, oy);
Canvas.LineTo(ox, oy1);
Canvas.moveto(ox1, oy1);
Canvas.LineTo(ox, oy1);
Canvas.moveto(ox1, oy1);
Canvas.LineTo(ox1, oy);
end;
Canvas.moveto(ox, oy);
Canvas.LineTo(x, oy);
Canvas.moveto(ox, oy);
Canvas.LineTo(ox, y);
Canvas.moveto(x, y);
Canvas.LineTo(ox, y);
Canvas.moveto(x, y);
Canvas.LineTo(x, oy);
OX1 := X;
OY1 := Y;
First := False;
end;
end;

procedure TForm1.FormMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
Mdown := true;
First := true;
OX := X;
OY := Y;
end;

procedure TForm1.FormMouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
Mdown := false;
OX := 0;
OY := 0;
OX1 := 0;
OY1 := 0;
end;
 
其实你可以把移动的每一个点的坐标记录下来(放在一个数组中),pen.style:=psdot;
然后用polyline()画线,这是在move事件中注意记录坐标的数组的维数随着鼠标移动而增大,up事件中
可以直接用polyline重画。
 
CANVAS就可以解决了.
 
在MouseDown函数里设置画刷的Mode为bsXOR,然后在MouseMove里画虚线,最后,把画刷
的Mode改为bsCopy画实线,虚线和实线是由画刷的style设置的。
 

Similar threads

D
回复
0
查看
2K
DelphiTeacher的专栏
D
D
回复
0
查看
2K
DelphiTeacher的专栏
D
D
回复
0
查看
1K
DelphiTeacher的专栏
D
D
回复
0
查看
2K
DelphiTeacher的专栏
D
D
回复
0
查看
1K
DelphiTeacher的专栏
D
后退
顶部