ucreatepen.pas

来自「Delphi Win32核心API参考光盘源码 本书包含了常用的Windows」· PAS 代码 · 共 66 行

PAS
66
字号
unit UCreatePen;

interface

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

type
  TForm1 = class(TForm)
    Button1: TButton;
    RadioGroup1: TRadioGroup;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}


procedure TForm1.Button1Click(Sender: TObject);
var
  Style: Integer;     // holds the pen styles
  PenHandle: HPen;    // the handle of the pen
begin
  {erase any previous image}
  Canvas.Brush.Color := clBtnFace;
  Canvas.FillRect(Rect(10, 10, 111, 111));

  {determine the pen style}
  case RadioGroup1.ItemIndex of
    0: Style := PS_SOLID;
    1: Style := PS_DASH;
    2: Style := PS_DOT;
    3: Style := PS_DASHDOT;
    4: Style := PS_DASHDOTDOT;
    5: Style := PS_NULL;
    6: Style := PS_INSIDEFRAME;
  end;

  {create the pen}
  PenHandle := CreatePen(Style, 1, 0);

  {instruct the canvas to use the new pen}
  Canvas.Pen.Handle := PenHandle;

  {draw a square with the pen}
  Canvas.MoveTo(10, 10);
  Canvas.LineTo(110, 10);
  Canvas.LineTo(110, 110);
  Canvas.LineTo(10, 110);
  Canvas.LineTo(10, 10);

  {delete the pen}
  DeleteObject(PenHandle);
end;

end.

⌨️ 快捷键说明

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