DrawTextRF(Text: String; Font: IGxFont; Brush: IGxBrush; Rect: IGxRectF; Format: IGxStringFormat);
Text. Text.
Font. Font that is used to display the text.
Brush. Brush that is used to render the text.
Rect. Real rectangular where the text is displayed.
Format. Text alignment format.
The DrawTextRF method displays the text in the specified rectangle with the specified format.
Executing the example requires a form with the button named Button1, the ImageBox component named. Add links to the Drawing, Forms system assemblies.
Sub Button1OnClick(Sender: Object; Args: IMouseEventArgs);
Var
BMP: IGxBitmap;
ImgFont: IGxFont;
ImgBrush: IGxBrush;
ImgFormat: IGxStringFormat;
Graph: IGxGraphics;
r: IGxRectF;
Begin
BMP := GxBitmap.CreateNew(ImageBox1.ClientWidth, ImageBox1.ClientHeight, GxPixelFormat.Format24bppRgb);
ImgFont := New GxFont.Create("Times New Roman", 16, GxFontStyle.BoldItalic, GxUnit.World);
ImgBrush := New GxSolidBrush.Create(GxColor.FromName("Red"));
ImgFormat := New GxStringFormat.Create;
ImgFormat.Alignment := GxStringAlignment.Center;
ImgFormat.LineAlignment := GxStringAlignment.Center;
ImgFormat.Trimming := GxStringTrimming.None;
Graph := GxGraphicsClass.FromImage(BMP);
r := New GxRectF.Create(0, 0, 0, 0);
r := Graph.MeasureTextRF("New Image", ImgFont, r, Null);
r.Width := r.Width / 2;
Graph.DrawTextRF("New Image", ImgFont, ImgBrush, r, ImgFormat);
ImageBox1.Image := BMP;
End Sub Button1OnClick;
After executing the example clicking the button in the ImageBox component displays a new bitmap image with truncated rectangle by width where the specified label with defined settings is rendered in the center.
See also: