Delphi 随鼠标移动的十字线的快速画法


本文整理自网络,侵删。

 

在鼠标移动事件中画当前点的十字坐标线时,为抹掉老线常采用刷新画面的方法,这样就产生了非常严重的闪烁现象。因此,我们采用在画新线前将老线抹去的方法就能很好的解决这个问题,而且速度非常快。现举例如下:


var  

  OldX, OldY: Longint;// 使用前初始化OldX:=-1;   


procedure TfrmMain.PaintBoxCMouseMove(Sender: TObject; Shift: TShiftState;   

  X, Y: Integer);   


  Procedure DrawCross(AX, AY: Integer);   

  begin  

    With PaintBoxC.Canvas do  

    begin  

      Pen.Color := CrossColor;   

      Pen.Style := CrossStyle;   

      Pen.Mode := pmXor;   

      Pen.Width := 1;   

      MoveTo(AX, 0);   

      LineTo(AX, PaintBoxC.Height);   

      MoveTo(0, AY);   

      LineTo(PaintBoxC.Width, AY);   

    end;   

  end;   


begin  

  if (OldX <> -1) then  

  begin  

    DrawCross(OldX, OldY); { 画旧十字线 }  

    OldX := -1;   

  end;   

  { 检查当前鼠标点是否在指定范围内 }  

  if PtInRect(Rect(0, 0, PaintBoxC.Width, PaintBoxC.Height), Point(X, Y)) then  

  begin  

    DrawCross(X, Y); { 在当前鼠标点画十字线 }  

    { 保存旧鼠标点 }  

    OldX := X;   

    OldY := Y;   

  end;   

end;

原文链接:http://www.tansoo.cn/?p=9

相关阅读 >>

Delphi 如何使用程序标识符检查程序是否已安装

Delphi获取本机的ip地址

Delphi 根据delta自动生成sql语句

Delphi writeln 写入一行文本

Delphi 判断文件类型函数

Delphi checkbox 透明

Delphi 如何在richedit控件里加入链接

Delphi xe [dcc32 fatal error] f2039 could not create output file 问题的解决

Delphi combobox 下拉事件

Delphi 调用api打开文件 使用系统默认打开方式进行打开

更多相关阅读请进入《Delphi》频道 >>



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...