Declaration function TextWidth(const Text: WideString): Integer; Description
Returns the width of text using the current
Font .
Note: This method calls
MeasureText
// Draw a semi-transparent text box onto a bitmap const Horz_Margin = 8; Vert_Margin = 3; Center_Text = False; var x, y: integer; tw, rw, rh: integer; iec: TIECanvas; ss: string; begin ss := 'This is my text'; x := 100; y := 100; iec := TIECanvas.Create( Bitmap.Canvas ); iec.Font.Size := 30; iec.Font.Style := [fsBold]; tw := iec.TextWidth(ss); rw := imax( tw + 2 * Horz_Margin, iec.TextWidth( ss ) + 2 * Horz_Margin ); rh := iec.TextHeight(ss) + 2 * Vert_Margin; if Center_Text then dec( x, rw div 2 ); iec.Brush.Color := clYellow; iec.Brush.Style := bsSolid; iec.Brush.Transparency := 196; iec.Pen.Color := clBlack; iec.Pen.Style := psSolid; iec.Rectangle( x, y, x + rw, y + rh ); iec.Brush.Style := bsClear; iec.TextOut(x + ( rw - tw ) div 2, y + Vert_Margin, ss); iec.Free; end;
Loading contents...