分别使用静态数组与动态数组建立一个区域 - 回复 "老A123" 的问题
分别使用静态数组与动态数组建立一个区域 - 回复 "老A123" 的问题
涂孟超 发表于3年前
分别使用静态数组与动态数组建立一个区域 - 回复 "老A123" 的问题
  • 发表于 3年前
  • 阅读 2
  • 收藏 0
  • 点赞 0
  • 评论 0

标题:腾讯云 新注册用户域名抢购1元起>>>   


问题来源: http://www.cnblogs.com/del/archive/2008/05/26/1207811.html#1475006

本例效果图:



代码文件:
unit Unit1;

interface

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

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

var
  Form1: TForm1;

implementation

{$R *.dfm}

{使用静态数组建立区域}
procedure TForm1.Button1Click(Sender: TObject);
var
  arr: array[0..3] of TPoint;
  rgn: HRGN;
  w,h: Integer;
begin
  w := ClientWidth;
  h := ClientHeight;
  arr[0] := Point(w div 2, 0);
  arr[1] := Point(w, h div 2);
  arr[2] := Point(w div 2, h);
  arr[3] := Point(0, h div 2);
  rgn := CreatePolygonRgn(arr, Length(arr), WINDING);

  {下面是描边和填充这个区域}
  Canvas.Brush.Color := clSilver;
  FrameRgn(Canvas.Handle, rgn, Canvas.Brush.Handle, 1, 1);

  Canvas.Brush.Style := bsCross;
  FillRgn(Canvas.Handle, rgn, Canvas.Brush.Handle);
end;

{使用动态数组建立区域}
procedure TForm1.Button2Click(Sender: TObject);
var
  arr: array of TPoint;
  rgn: HRGN;
  w,h: Integer;
begin
  SetLength(arr, 4);
  w := ClientWidth;
  h := ClientHeight;
  arr[0] := Point(w div 2, 0);
  arr[1] := Point(w, h div 2);
  arr[2] := Point(w div 2, h);
  arr[3] := Point(0, h div 2);
  rgn := CreatePolygonRgn(arr[0], Length(arr), WINDING); {第一个参数是数组的起点}

  {下面是描边和填充这个区域}
  Canvas.Brush.Color := clRed;
  FrameRgn(Canvas.Handle, rgn, Canvas.Brush.Handle, 1, 1);
  Canvas.Brush.Style := bsCross;
  FillRgn(Canvas.Handle, rgn, Canvas.Brush.Handle);
end;

end.

 
 
 
 
 

 

 

  

窗体文件:
object Form1: TForm1
  Left = 0
  Top = 0
  Caption = 'Form1'
  ClientHeight = 175
  ClientWidth = 289
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'Tahoma'
  Font.Style = []
  OldCreateOrder = False
  PixelsPerInch = 96
  TextHeight = 13
  object Button1: TButton
    Left = 208
    Top = 113
    Width = 75
    Height = 25
    Caption = 'Button1'
    TabOrder = 0
    OnClick = Button1Click
  end
  object Button2: TButton
    Left = 208
    Top = 144
    Width = 75
    Height = 25
    Caption = 'Button2'
    TabOrder = 1
    OnClick = Button2Click
  end
end

 
 
 
 
 

 

 

  

共有 人打赏支持
粉丝 12
博文 2004
码字总数 14107
×
涂孟超
如果觉得我的文章对您有用,请随意打赏。您的支持将鼓励我继续创作!
* 金额(元)
¥1 ¥5 ¥10 ¥20 其他金额
打赏人
留言
* 支付类型
微信扫码支付
打赏金额:
已支付成功
打赏金额: