There are five ways to create a region for GDI +:
1. Create a rectangle (rectangular area );
2. Create a path;
3. It is created based on the handles of the GDI region;
4. Create a region based on the data obtained from the region;
5. No parameter is set.
This example demonstrates the first three methods.
In this example:
Code file:
Unit unit1; interfaceuses 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 (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); {Based on the rectangle (rectangular area)} 1: begin {Based on the path} path: = tgpgraphicspath. create; Path. addellipse (RT); RGN: = tgpregion. create (PATH); Path. free; end; 2: begin {created based on the handle of the GDI region} rgnhandle: = createpolygonrgn (PTS, length (PTS), winding); RGN: = tgpregion. create (rgnhandle); deleteobject (rgnhandle); 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.
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 endend