LineTo函数在mousemove中怎么能在移动过程中只有一条线(50分)

  • 主题发起人 主题发起人 bota
  • 开始时间 开始时间
B

bota

Unregistered / Unconfirmed
GUEST, unregistred user!
要求测距,现在mousemove中使用LineTo函数来画线,鼠标移动后会出现无数条线,怎么能让将前一个鼠标点的线去掉,只需要当前鼠标点的这条线就可以了<br>procedure TForm1.MouseMove(Sender: TObject; Shift: TShiftState; X,<br> &nbsp;Y: Integer);<br>begin<br> &nbsp; &nbsp; MoveToEx(m_lngMapDc,ScrX,ScrY,TmpPoint);<br> &nbsp; &nbsp; LineTo(m_lngMapDc,X,Y);<br>end;
 
你设一组全局变量,目的是纪录每次划线的前一条线的坐标,然后你在每次划线的时候先清除前一条线
 
画方框的代码,不想改了,你自己改改<br><br>var<br> &nbsp;MouseButtonDown: Boolean;<br> &nbsp;Rect: TRect;<br>//mousedown<br> &nbsp; &nbsp;MouseButtonDown := True;<br> &nbsp; &nbsp;Screen.Cursor := crCross;<br> &nbsp; &nbsp;with Rect do<br> &nbsp; &nbsp;begin<br> &nbsp; &nbsp; &nbsp;Left := x;<br> &nbsp; &nbsp; &nbsp;Top := y;<br> &nbsp; &nbsp; &nbsp;Right := x;<br> &nbsp; &nbsp; &nbsp;Bottom := y;<br> &nbsp; &nbsp;end;<br>//mousemove<br> &nbsp; &nbsp;if MouseButtonDown then<br> &nbsp; &nbsp;begin<br> &nbsp; &nbsp; &nbsp;Panel1.Canvas.DrawFocusRect(Rect);<br> &nbsp; &nbsp; &nbsp;with Rect do<br> &nbsp; &nbsp; &nbsp;begin<br> &nbsp; &nbsp; &nbsp; &nbsp;Right := x;<br> &nbsp; &nbsp; &nbsp; &nbsp;Bottom := y;<br> &nbsp; &nbsp; &nbsp;end;<br> &nbsp; &nbsp; &nbsp;Panel1.Canvas.DrawFocusRect(Rect);<br> &nbsp; &nbsp;end;<br>//mouseup<br> &nbsp; &nbsp;MouseButtonDown := False;<br> &nbsp; &nbsp;Screen.Cursor := crdefault;
 
解决了,呵呵,刷新一下就好了,它自己会没掉的
 
多人接受答案了。
 

Similar threads

D
回复
0
查看
2K
DelphiTeacher的专栏
D
D
回复
0
查看
1K
DelphiTeacher的专栏
D
D
回复
0
查看
2K
DelphiTeacher的专栏
D
S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
D
回复
0
查看
1K
DelphiTeacher的专栏
D
后退
顶部