Intersect {intersection} Union {Union} XOR _ {minus intersection} exclude {minus} complement {not intersection} // The region of GDI + can be carried out with three objects: rectangle, path, and another region. operation.
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: = 'channel, rectangle, intersect, union, XOR _, exclude, complement'; radiogroup1.itemindex: = 0; end; Procedure tform1.formpaint (Sender: tobject); var G: tgpgraphics; p: tgppen; Path: tgpgraphicspath; B: tgpbrush; RGN: tgpregion; RT: tgprect; begin G: = tgpgraphics. create (canvas. handle); P: = tgppen. create (makecolor (100,255, 0, 0); B: = tgphatchbrush. create (hatchstylesmallgrid, aclsilver, aclcornflowerblue); {prepare paths} path: = tgpgraphicspath. create; Path. addellipse (20, 20,100, 80); {create a region based on the path} RGN: = tgpregion. create (PATH); {get the range} // RGN. getbounds (RT, g); Path. getbounds (RT); {move down the rectangle and use this rectangle to perform operations} RT. y: = RT. Y + RT. height Div 2; Case radiogroup1.itemindex of 1: RGN: = tgpregion. create (RT); 2: RGN. intersect (RT); 3: RGN. union (RT); 4: RGN. XOR _ (RT); 5: RGN. exclude (RT); 6: RGN. complement (RT); end; G. fillregion (B, RGN); G. drawpath (p, PATH); G. drawrectangle (p, RT); B. free; RGN. free; p. free; G. free; end; Procedure tform1.radiogroup1click (Sender: tobject); begin repaint; end.
Form file:
Object form1: tform1 left = 0 Top = 0 caption = 'form1' clientheight = 167 clientwidth = 238 color = clbtnface font. charset = default_charset font. color = clwindowtext font. height =-11 font. name = 'tahoma 'font. style = [] oldcreateorder = false position = pow.topcenter oncreate = formcreate onpaint = formpaint pixelsperinch = 96 textheight = 13 object radiogroup1: tradiogroup left = 137 Top = 8 width = 91 Height = 151 caption = 'radiogroup1' taborder = 0 onclick = radiogroup1click endend