为什么80%的码农都做不了架构师?>>>
代码文件:
unit Unit1;interfaceusesWindows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,Dialogs, StdCtrls, ComCtrls, ExtCtrls;typeTForm1 = 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;varForm1: TForm1;implementation{$R *.dfm}uses GDIPOBJ, GDIPAPI, TypInfo;varsfFlag: Integer;procedure TForm1.FormCreate(Sender: TObject);
窗体文件:
vari: Integer;
beginfor i := 0 to 2 doRadioGroup1.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);
varg: TGPGraphics;b: TGPBrush;font: TGPFont;sf: TGPStringFormat;rect: TGPRectF;
beging := 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 TForm1.RadioGroup1Click(Sender: TObject);
beginPaintBox1.Repaint;
end;procedure TForm1.RadioGroup2Click(Sender: TObject);
beginPaintBox1.Repaint;
end;procedure TForm1.RadioGroup3Click(Sender: TObject);
begincase RadioGroup3.ItemIndex of0: 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.
object Form1: TForm1Left = 0Top = 0Caption = 'Form1'ClientHeight = 348ClientWidth = 383Color = clBtnFaceFont.Charset = DEFAULT_CHARSETFont.Color = clWindowTextFont.Height = -11Font.Name = 'Tahoma'Font.Style = []OldCreateOrder = FalsePosition = poDesktopCenterOnCreate = FormCreatePixelsPerInch = 96TextHeight = 13object PaintBox1: TPaintBoxLeft = 8Top = 195Width = 367Height = 145OnPaint = PaintBox1Paintendobject RadioGroup1: TRadioGroupLeft = 239Top = 8Width = 136Height = 81Caption = 'RadioGroup1'TabOrder = 0OnClick = RadioGroup1Clickendobject RadioGroup2: TRadioGroupLeft = 239Top = 104Width = 136Height = 85Caption = 'RadioGroup2'TabOrder = 1OnClick = RadioGroup2Clickendobject RadioGroup3: TRadioGroupLeft = 8Top = 8Width = 225Height = 181Caption = 'RadioGroup3'TabOrder = 2OnClick = RadioGroup3Clickend
文本对齐方式:
end
Delphi | 微软 | 说明 |
---|---|---|
StringAlignmentCenter | Center | 指定文本在布局矩形中居中对齐。 |
StringAlignmentFar | Far | 指定文本远离布局矩形的原点位置对齐。在左到右布局中,远端位置是右。在右到左布局中,远端位置是左。 |
StringAlignmentNear | Near | 指定文本靠近布局对齐。在左到右布局中,近端位置是左。在右到左布局中,近端位置是右。 |
文本格式化标志:
Delphi | 微软 | 说明 |
---|---|---|
StringFormatFlagsDirectionRightToLeft | DirectionRightToLeft | 按从右向左的顺序显示文本。 |
StringFormatFlagsDirectionVertical | DirectionVertical | 文本垂直对齐。 |
StringFormatFlagsDisplayFormatControl | DisplayFormatControl | 控制字符(如从左到右标记)随具有代表性的标志符号一起显示在输出中。 |
StringFormatFlagsFitBlackBox | FitBlackBox | 允许部分字符延伸该字符串的布局矩形。默认情况下,将重新定位字符以避免任何延伸。 |
StringFormatFlagsLineLimit | LineLimit | 在格式化的矩形中只布置整行。默认情况下,这种布置要继续到文本的结尾为止,或者到由于剪辑而不再有可见的行为止,看哪一种情况先发生。注意,此默认设置允许不是行高整数倍的格式化矩形将最后一行部分地遮住。若要确保看到的都是整行,请指定此值,并仔细地提供格式化矩形,使其高度至少为一个行高。 |
StringFormatFlagsMeasureTrailingSpaces | MeasureTrailingSpaces | 包括每一行结尾处的尾随空格。在默认情况下,MeasureString 方法返回的边框都将排除每一行结尾处的空格。设置此标记以便在测定时将空格包括进去。 |
StringFormatFlagsNoClip | NoClip | 允许显示标志符号的伸出部分和延伸到边框外的未换行文本。在默认情况下,延伸到边框外侧的所有文本和标志符号部分都被剪裁。 |
StringFormatFlagsNoFontFallback | NoFontFallback | 对于请求的字体中不支持的字符,禁用回退到可选字体。缺失的任何字符都用缺失标志符号的字体显示,通常是一个空的方块。 |
StringFormatFlagsNoWrap | NoWrap | 在矩形内设置格式时,禁用文本换行功能。当传递的是点而不是矩形时,或者指定的矩形行长为零时,已隐含此标记。 |