Learn more about GDI + [45]: text output-format the output in a rectangle

Source: Internet
Author: User
In this example:


Code File:
Unit unit1; interfaceuses windows, messages, sysutils, variants, classes, graphics, controls, forms, dialogs, classes, comctrls, extctrls; Type tform1 = Class (tform) radiogroup1: tradiogroup; radiogroup2: tradiogroup; radiogroup3: tradiogroup; paintbox1: tpaintbox; Procedure formcreate (Sender: tobject); Procedure alert (Sender: tobject ); procedure paintbox1paint (Sender: tobject); Procedure radiogroup3click (Sender: tobject); end; var form1: tform1; implementation {$ R *. DFM} uses gdipobj, gdipapi, typinfo; var sfflag: integer; Procedure tform1.formcreate (Sender: tobject); var I: integer; begin for I: = 0 to 2 do radiogroup1.items. add (getenumname (typeinfo (tstringalignment), I); radiogroup1.itemindex: = 0; radiogroup2.items: = radiogroup1.items; radiogroup2.itemindex: = 0; radiogroup3.items. commatext: = 'string', '+ 'string',' + 'stringformatflagsnofitblackbox, '+ 'stringformatflagsdisplayformatcontrol,' + 'stringformatflagsnofontfallback, '+ 'struct',' + 'stringformatflagsnowrap, '+ 'require,' + 'stringformatflagsnoclip '; end; Procedure require (Sender: tobject); var G: tgpgraphics; B: tgpbrush; Font: tgpfont; SF: tgpstringformat; rect: tgprectf; begin G: = tgpgraphics. create (paintbox1.canvas. handle); B: = tgpsolidbrush. create ($ ff000000); G. settextrenderinghint (textrenderinghintantialias); Font: = tgpfont. create ('arial Black', 22); SF: = tgpstringformat. create; SF. setformatflags (stringformatflagsnoclip); SF. setalignment (tstringalignment (radiogroup1.itemindex); SF. setlinealignment (tstringalignment (radiogroup2.itemindex); SF. setformatflags (sfflag); rect. x: = 0; rect. y: = 0; rect. width: = paintbox1.clientwidth; rect. height: = paintbox1.clientheight; G. drawstring ('delphi ',-1, Font, rect, SF, B); SF. free; font. free; B. free; G. free; end; Procedure extract (Sender: tobject); begin paintbox1.repaint; end; Procedure extract (Sender: tobject); begin paintbox1.repaint; end; Procedure extract (Sender: tobject ); begin case radiogroup3.itemindex of 0: sfflag: = week; 1: sfflag: = week; 2: sfflag: = stringformatflagsnofitblackbox; 3: sfflag: = week; 4: sfflag: = Week; 5: sfflag: = release; 6: sfflag: = stringformatflagsnowrap; 7: sfflag: = release; 8: sfflag: = stringformatflagsnoclip; end; paintbox1.repaint; end.
 
   
 

Form file:

 Object form1: tform1 left = 0 Top = 0 caption = 'form1 'clientheight = 348 clientwidth = 383 color = clbtnface font. charset = default_charset font. color = clwindowtext font. height =-11 font. name = 'tahoma 'font. style = [] oldcreateorder = false position = pow.topcenter oncreate = formcreate pixelsperinch = 96 textheight = 13 object paintbox1: tpaintbox left = 8 Top = 195 width = 367 Height = 145 onpaint = paintbox1paint end object radiogroup1: tradiogroup left = 239 Top = 8 width = 136 Height = 81 caption = 'radiogroup1' taborder = 0 onclick = radiogroup1click end object radiogroup2: tradiogroup left = 239 Top = 104 width = 136 Height = 85 caption = 'radiogroup2' taborder = 1 onclick = radiogroup2click end object radiogroup3: tradiogroup left = 8 Top = 8 width = 225 Height = 181 caption = 'radiogroup3' taborder = 2 onclick = radiogroup3click endend

   

Text alignment:

Delphi Microsoft Description
Stringalignmentcenter Center Specifies the center alignment of text in the layout rectangle.
Stringalignmentfar Far Specifies that the text is aligned away from the origin of the layout rectangle. In the left-to-right layout, the remote location is right. In the right-to-left layout, the remote location is left.
Stringalignmentnear Near Specifies that the text is aligned close to the layout. In the left-to-right layout, the position of the near end is left. In the right-to-left layout, the position near the end is right.

Text Format flag:

Delphi Microsoft Description
Stringformatflagsdirectionrighttoleft Directionrighttoleft Display text in the order from right to left.
Stringformatflagsdirectionvertical Directionvertical Vertical text alignment.
Stringformatflagsdisplayformatcontrol Displayformatcontrol Control characters (such as from left to right) are displayed in the output together with representative symbols.
Stringformatflagsfitblackbox Fitblackbox Some characters are allowed to extend the layout rectangle of the string. By default, the characters are located to avoid any extension.
Stringformatflagslinelimit Linelimit Only the whole line is arranged in the formatted rectangle. By default, this layout will continue until the end of the text, or until there are no visible lines due to editing. Note: This default setting allows a formatted rectangle that is not an integer multiple of the row to partially hide the last row. To ensure that all rows are displayed, specify this value and carefully format the rectangle so that the height is at least one row height.
Stringformatflagsmeasuretrailingspaces Measuretrailingspaces It includes trailing spaces at the end of each line. By default, measurestring
All borders returned by the method exclude spaces at the end of each line. Set this flag to include spaces during the test.
Stringformatflagsnoclip Noclip Displays the unwrapped text extending out of the logo and extending out of the border. By default, all text and symbolic parts that extend beyond the border are cropped.
Stringformatflagsnofontfallback Nofontfallback For characters not supported in the requested font, disable rollback to the optional font. Any missing characters are displayed in the font of the missing symbol, which is usually an empty square.
Stringformatflagsnowrap Nowrap When the format is set in the rectangle, the text line feed function is disabled. This flag is hidden when it is passed as a vertex rather than a rectangle, or when the length of the specified rectangle is zero.

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.