There are five ways to establish GDI + areas:
1, according to a rectangle to establish (rectangular region);
2, according to the path to establish;
3, according to the GDI region to establish the handle;
4, based on the data obtained from the region to establish;
5, no parameters to establish.
This example demonstrates the first three methods of establishment.
This example effect chart:
Code files: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: = ' Rectangular channel, elliptical channel, Polygon channel ';
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 (A, M, 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); {Based on rectangle (rectangular area)}
1:begin {set based on path}
Path: = Tgpgraphicspath.create;
Path. AddEllipse (RT);
Rgn: = tgpregion.create (path);
Path. Free;
End
2:begin {Based on the handle of the GDI region}
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.
Form file: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