zoukankan      html  css  js  c++  java
  • 再学 GDI+[72]: 区域(1) 建立区域

    建立 GDI+ 的区域有五种办法:

    1、根据一个矩形建立(矩形区域);
    2、根据路径建立;
    3、根据 GDI 区域的句柄建立;
    4、根据从区域中获取的数据建立;
    5、无参数建立.

    本例演示了前三种建立方法.

    本例效果图:



    代码文件:
    unit Unit1;
    
    interface
    
    uses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls, ExtCtrls;
    
    type
      TForm1 = class(TForm)
        RadioGroup1: TRadioGroup;
        procedure FormCreate(Sender: TObject);
        procedure FormPaint(Sender: TObject);
        procedure RadioGroup1Click(Sender: TObject);
      end;
    
    var
      Form1: TForm1;
    
    implementation
    
    {$R *.dfm}
    
    uses GDIPOBJ, GDIPAPI;
    
    procedure TForm1.FormCreate(Sender: TObject);
    begin
      RadioGroup1.Items.CommaText := '矩形通道,椭圆形通道,多边形通道';
      RadioGroup1.ItemIndex := 0;
    end;
    
    procedure TForm1.FormPaint(Sender: TObject);
    var
      rt: TGPRect;
      pts: array[0..2] of TPoint;
      RgnHandle: HRGN;
      g: TGPGraphics;
      path: TGPGraphicsPath;
      b: TGPBrush;
      rgn: TGPRegion;
    begin
      rt := MakeRect(20, 20, 100, ClientHeight-40);
      pts[0] := Point(rt.X + rt.Width div 2, rt.Y);
      pts[1] := Point(rt.X, rt.Y + rt.Height);
      pts[2] := Point(rt.X + rt.Width, rt.Y + rt.Height);
    
      case RadioGroup1.ItemIndex of
        0: rgn := TGPRegion.Create(rt);       {根据矩形建立(矩形区域)}
        1: begin                              {根据路径建立}
             path := TGPGraphicsPath.Create;
             path.AddEllipse(rt);
             rgn := TGPRegion.Create(path);
             path.Free;
           end;
        2: begin                              {根据 GDI 区域的句柄建立}
             RgnHandle := CreatePolygonRgn(pts, Length(pts), WINDING);
             rgn := TGPRegion.Create(RgnHandle);
             DeleteObject(RgnHandle);
           end;
      end;
    
      g := TGPGraphics.Create(Canvas.Handle);
      b := TGPHatchBrush.Create(HatchStyleDiagonalCross, aclSilver, aclGray);
      g.FillRegion(b, rgn);
    
      b.Free;
      rgn.Free;
      g.Free;
    end;
    
    procedure TForm1.RadioGroup1Click(Sender: TObject);
    begin
      Repaint;
    end;
    
    end.
    
    窗体文件:
    object Form1: TForm1
      Left = 0
      Top = 0
      Caption = 'Form1'
      ClientHeight = 137
      ClientWidth = 238
      Color = clBtnFace
      Font.Charset = DEFAULT_CHARSET
      Font.Color = clWindowText
      Font.Height = -11
      Font.Name = 'Tahoma'
      Font.Style = []
      OldCreateOrder = False
      Position = poDesktopCenter
      OnCreate = FormCreate
      OnPaint = FormPaint
      PixelsPerInch = 96
      TextHeight = 13
      object RadioGroup1: TRadioGroup
        Left = 137
        Top = 8
        Width = 91
        Height = 121
        Caption = 'RadioGroup1'
        TabOrder = 0
        OnClick = RadioGroup1Click
      end
    end
    
  • 相关阅读:
    2016/2/22 1、DOM的基本概念 2、Window对象操作 3、Windows.history对象 4、Window.location对象 5、Window.status对象
    2016/2/21 JavaScript简介
    2016/2/19 position: fixed absolute relative z-index float 半透明效果
    2016/2/19 css样式表 Cascading Style Sheet 叠层样式表 美化HTML网页
    2016/2/18 html 图片热点,网页划区,拼接,表单
    2016/2/18 html 标签 表格
    重载
    面向对象 Java练习
    Car 加油
    大乐透 Java随机码
  • 原文地址:https://www.cnblogs.com/del/p/1232149.html
Copyright © 2011-2022 走看看