subtractrectu.pas

来自「delphi win32api编程」· PAS 代码 · 共 55 行

PAS
55
字号
unit SubtractRectU;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs;

type
  TForm1 = class(TForm)
    procedure FormPaint(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.FormPaint(Sender: TObject);
var
  Rect1, Rect2, Subtract: TRect;    // holds the rectangles
begin
  {set the coordinates of the two test rectangles}
  SetRect(Rect1, 10, 10, 110, 110);
  SetRect(Rect2, 60, 10, 160, 160);

  {subtract rectangle 2 from rectangle 1}
  SubtractRect(Subtract, Rect1, Rect2);

  with Form1.Canvas do
  begin
    {initialize canvas objects to draw outlines}
    Brush.Style := bsClear;
    Pen.Style := psSolid;

    {draw the outlines of rectangle 1 and 2}
    Rectangle(Rect1.Left, Rect1.Top, Rect1.Right, Rect1.Bottom);
    Rectangle(Rect2.Left, Rect2.Top, Rect2.Right, Rect2.Bottom);

    {initialize canvas objects to draw the result}
    Brush.Style := bsSolid;
    Brush.Color := clRed;

    {fill the resulting rectangle with red}
    FillRect(Subtract);
  end;
end;

end.

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?