zoukankan      html  css  js  c++  java
  • Delphi 的绘图功能[12] TPen 类(下) : 学习橡皮线

    //奇妙的异或运算, 就这些简单的代码, 反复点击按钮...
    
    procedure TForm1.Button1Click(Sender: TObject);
    begin
      Canvas.Pen.Color := clYellow; {指定笔颜色为黄色}
      Canvas.Pen.Width := 20;       {笔宽 20}
      Canvas.Pen.Mode := pmXor;     {指定画笔模式为: 画笔色与背景色的异或运算}
    
      {画线}
      Canvas.MoveTo(0,0);
      Canvas.LineTo(ClientWidth,ClientHeight);
    end;
    
    //效果图:

    //做一个橡皮线的示例:
    
    unit Unit1;
    
    interface
    
    uses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls;
    
    type
      TForm1 = class(TForm)
        procedure FormMouseDown(Sender: TObject; Button: TMouseButton;
          Shift: TShiftState; X, Y: Integer);
        procedure FormMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
        procedure FormMouseUp(Sender: TObject; Button: TMouseButton;
          Shift: TShiftState; X, Y: Integer);
      end;
    
    var
      Form1: TForm1;
    
    implementation
    
    {$R *.dfm}
    
    var
      x1,y1,x2,y2: Integer; {直线两个端点的坐标}
      f: Boolean;           {判断鼠标是否点下}
    
    
    procedure TForm1.FormMouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    begin
      x1 := X; y1 := Y;
      x2 := X; y2 := Y;
      Canvas.Pen.Color := clRed;
      Canvas.Pen.Width := 2;
      Canvas.Pen.Mode := pmXor;
      f := True;
    end;
    
    procedure TForm1.FormMouseMove(Sender: TObject; Shift: TShiftState; X,
      Y: Integer);
    begin
      if f then
      begin
        {擦除}
        Canvas.MoveTo(x1, y1);
        Canvas.LineTo(x2, y2);
    
        x2 := X; y2 := y;
    
        {重绘}
        Canvas.MoveTo(x1, y1);
        Canvas.LineTo(x2, y2);
      end;
    end;
    
    procedure TForm1.FormMouseUp(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    begin
      if f then
      begin
        {画出确定的线}
        Canvas.Pen.Mode := pmCopy;
        Canvas.MoveTo(x1, y1);
        Canvas.LineTo(x2, y2);
        f := not f;
      end;
    end;
    
    end.
    
    //效果图:


  • 相关阅读:
    Swift _ OC _ 混编
    CoreAnimation 寄宿图
    CoreAnimation 开篇
    iOS 杂笔-26(苹果禁用热更新)
    Swift_TableView(delegate,dataSource,prefetchDataSource 详解)
    Swift_ScrollView _ API详解
    插入排序_c++
    选择排序_c++
    冒泡排序_c++
    Swift_协议
  • 原文地址:https://www.cnblogs.com/del/p/1072335.html
Copyright © 2011-2022 走看看