Re-learning gdi+[45]: Text output

Source: Internet
Author: User

This example effect chart:

Code files:Unit Unit1;
Interface
Uses
Windows, Messages, sysutils, variants, Classes, Graphics, Controls, Forms,
Dialogs, Stdctrls, Comctrls, Extctrls;
Type
TForm1 = Class (Tform)
Radiogroup1:tradiogroup;
Radiogroup2:tradiogroup;
Radiogroup3:tradiogroup;
Paintbox1:tpaintbox;
Procedure Formcreate (Sender:tobject);
Procedure Radiogroup1click (Sender:tobject);
Procedure Radiogroup2click (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: = ' stringformatflagsdirectionrighttoleft, ' +
' Stringformatflagsdirectionvertical, ' +
' Stringformatflagsnofitblackbox, ' +
' Stringformatflagsdisplayformatcontrol, ' +
' Stringformatflagsnofontfallback, ' +
' Stringformatflagsmeasuretrailingspaces, ' +
' Stringformatflagsnowrap, ' +
' Stringformatflagslinelimit, ' +
' Stringformatflagsnoclip ';
End
Procedure Tform1.paintbox1paint (Sender:tobject);
Var
G:tgpgraphics;
B:tgpbrush;
Font:tgpfont;
Sf:tgpstringformat;
RECT:TGPRECTF;
Begin
G: = Tgpgraphics.create (PaintBox1.Canvas.Handle);
B: = Tgpsolidbrush.create ($FF 000000);
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 Tform1.radiogroup1click (Sender:tobject);
Begin
Paintbox1.repaint;
End
Procedure Tform1.radiogroup2click (Sender:tobject);
Begin
Paintbox1.repaint;
End
Procedure Tform1.radiogroup3click (Sender:tobject);
Begin
Case Radiogroup3.itemindex of
0:sfflag: = Stringformatflagsdirectionrighttoleft;
1:sfflag: = stringformatflagsdirectionvertical;
2:sfflag: = Stringformatflagsnofitblackbox;
3:sfflag: = Stringformatflagsdisplayformatcontrol;
4:sfflag: = Stringformatflagsnofontfallback;
5:sfflag: = stringformatflagsmeasuretrailingspaces;
6:sfflag: = Stringformatflagsnowrap;
7:sfflag: = Stringformatflagslinelimit;
8:sfflag: = Stringformatflagsnoclip;
End
Paintbox1.repaint;
End
End.

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.