本例效果图:

WinAPI: InvertRect - 翻转矩形中像素的颜色
unit Unit1;

interface

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

type
  TForm1 = class(TForm)
    Button1: TButton;
    Button2: TButton;
    procedure FormCreate(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

var
  R: TRect;

procedure TForm1.FormCreate(Sender: TObject);
begin
  Button1.Caption := '绘制矩形';
  Button2.Caption := '反色';
  Self.Color := clWhite;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  R := Bounds(20, 20, 150, 100);
  Randomize;
  Canvas.Brush.Color := Random($FFFFFF);
  Canvas.Pen.Color := Random($FFFFFF);
  Canvas.Pen.Width := 10;
  Canvas.Rectangle(R);
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
  InvertRect(Canvas.Handle, R);
end;

end.

相关文章:

  • 2022-12-23
  • 2021-10-20
  • 2022-12-23
  • 2021-04-18
  • 2022-12-23
  • 2021-12-16
  • 2021-10-10
猜你喜欢
  • 2022-12-23
  • 2021-06-04
  • 2022-01-18
  • 2022-12-23
  • 2022-12-23
  • 2021-07-26
  • 2021-12-02
相关资源
相似解决方案