Learn more about GDI + [72]: Region (1)-create Region

Source: Internet
Author: User
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
 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.