• 画图学习 [2]


    unit Unit1;

    interface

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

    type
    TForm1
    = class(TForm)
    btn1: TButton;
    pnl1: TPanel;
    pb1: TPaintBox;
    procedure btn1Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    private
    { Private declarations }
    public
    { Public declarations }
    end;

    var
    Form1: TForm1;

    implementation

    {$R *.dfm}
    var
    cvs: TCanvas;

    procedure TForm1.btn1Click(Sender: TObject);
    begin
    pb1.Canvas.Brush.Color :
    = clYellow;
    pb1.Canvas.FillRect(pb1.ClientRect);

    cvs :
    = TCanvas.Create;
    cvs.Handle :
    = GetDC(pnl1.Handle);
    cvs.Brush.Color :
    = clBlue;
    cvs.FillRect(pnl1.ClientRect);
    cvs.Free;
    end;


    procedure TForm1.FormCreate(Sender: TObject);
    begin
    Canvas.Pen.Color :
    = clGreen;
    Canvas.Pen.Width :
    = 2;
    Canvas.Brush.Color :
    = clWhite;
    end;

    end.

    unit Unit1;

    interface

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

    type
    TForm1
    = class(TForm)
    btn1: TButton;
    btn2: TButton;
    procedure btn1Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure btn2Click(Sender: TObject);
    private
    { Private declarations }
    public
    { Public declarations }
    end;

    var
    Form1: TForm1;

    implementation

    {$R *.dfm}


    procedure TForm1.btn1Click(Sender: TObject);
    var
    pts:
    array[0..3] of TPoint;
    begin
    pts[
    0].X := btn1.Left+btn1.Width div 2;
    pts[
    0].Y := 10;
    pts[
    1].X := btn1.Left;
    pts[
    1].Y := 100;
    pts[
    2].X := btn1.Left+btn1.Width div 2;
    pts[
    2].Y := 200;
    pts[
    3].X := btn1.Left+btn1.Width;
    pts[
    3].Y := 100;

    Canvas.Polygon(pts);
    end;


    procedure TForm1.btn2Click(Sender: TObject);
    var
    pts:
    array[0..3] of TPoint;
    begin
    pts[
    0].X := btn2.Left+btn2.Width div 2;
    pts[
    0].Y := 10;
    pts[
    1].X := btn2.Left;
    pts[
    1].Y := 100;
    pts[
    2].X := btn2.Left+btn2.Width div 2;
    pts[
    2].Y := 200;
    pts[
    3].X := btn2.Left+btn2.Width;
    pts[
    3].Y := 100;
    Canvas.Polyline(pts);
    end;

    procedure TForm1.FormCreate(Sender: TObject);
    begin
    Canvas.Pen.Color :
    = clYellow;
    Canvas.Pen.Width :
    = 2;
    Canvas.Brush.Color :
    = clred;
    end;

    end.

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

  • 相关阅读:
    异常处理
    PAT——1048. 数字加密
    PAT——1047. 编程团体赛
    PAT——1046. 划拳
    PAT——1045. 快速排序(25)
    PAT——1044. 火星数字
    PAT——1043. 输出PATest
    PAT——1042. 字符统计
    PAT——1041. 考试座位号
    PAT——1040. 有几个PAT
  • 原文地址:https://www.cnblogs.com/ljjphysics/p/2052780.html
Copyright © 2020-2023  润新知