In this example:
Code File:
Unit unit1; interfaceuses windows, messages, sysutils, variants, classes, graphics, controls, forms, dialogs, stdctrls; Type tform1 = Class (tform) button1: tbutton; button2: tbutton; procedure button1click (Sender: tobject); Procedure button2click (Sender: tobject); end; var form1: tform1; implementation {$ R *. DFM} uses gdipobj, gdipapi; Procedure tform1.button1click (Sender: tobject); var G: tgpgraphics; SB: tgpsolidbrush; Font: tgpfont; begin G: = tgpgraphics. create (canvas. handle); SB: = tgpsolidbrush. create (aclblack); {specify the font name and font size to create a tgpfont class} Font: = tgpfont. create ('body', 9); G. drawstring ); {parameter 2 is-1, indicating that all specified characters are output; parameter 4 must be a tgppointf structure} font. free; sb. free; G. free; end; Procedure tform1.button2click (Sender: tobject); var G: tgpgraphics; SB: tgpsolidbrush; Font: tgpfont; begin G: = tgpgraphics. create (canvas. handle); SB: = tgpsolidbrush. create (aclblack); {create a tgpfont class by using features of other DC; but it seems that it cannot inherit all features, such as font color} canvas. font. name: = ''; canvas. font. size: = 9; Font: = tgpfont. create (canvas. handle); G. drawstring. free; sb. free; G. free; end.
Form file:
Object form1: tform1 left = 0 Top = 0 caption = 'form1' clientheight = 105 clientwidth = 282 color = clbtnface font. charset = default_charset font. color = clwindowtext font. height =-11 font. name = 'tahoma 'font. style = [] oldcreateorder = false position = podesktopcenter pixelsperinch = 96 textheight = 13 object button1: tbutton left = 64 Top = 68 width = 75 Height = 25 caption = 'button1' taborder = 0 onclick = button1click end object button2: tbutton left = 145 Top = 68 width = 75 Height = 25 caption = 'button2' taborder = 1 onclick = button2click endend