⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 urectangle.pas

📁 DelphiWin32核心API参考光盘内容.是学习书籍中的源码,便于学习.
💻 PAS
字号:
unit URectangle;

interface

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

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

var
  Form1: TForm1;
  BrushOffset: Integer;     // holds the current brush offset

implementation

{$R *.DFM}

procedure TForm1.Timer1Timer(Sender: TObject);
var
  BrushPt: TPoint;                   // holds the current brush origin
  BrushHndl, OldBrush: HBRUSH;       // handles to brushes
  FormDC: HDC;                       // the form's device context
begin
  {retrieve the form's device context}
  FormDC := GetDC(Form1.Handle);

  {increment the brush offset}
  Inc(BrushOffset);

  {create a hatched brush}
  BrushHndl := CreateHatchBrush(HS_DIAGCROSS, clRed);

  {set the brushes origin}
  SetBrushOrgEx(FormDC, BrushOffset, BrushOffset, nil);

  {select the brush into the device context}
  OldBrush := SelectObject(FormDC, BrushHndl);

  {retrieve the current brush origin}
  GetBrushOrgEx(FormDC, BrushPt);

  {if the brush origin is beyond the limit, reset it}
  if BrushPt.X>7 then
  begin
    BrushOffset := 0;
    SetBrushOrgEx(FormDC, BrushOffset, BrushOffset, nil);
  end;

  {draw the rectangle}
  Rectangle(FormDC, 10, 10, 110, 110);

  {delete the new brush}
  SelectObject(FormDC, OldBrush);
  DeleteObject(BrushHndl);

  {release the form's device context}
  ReleaseDC(Form1.Handle, FormDC);
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  {initialize the brush offset}
  BrushOffset := 0;
end;

end.

⌨️ 快捷键说明

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