RAD Studio VCL Reference
|
Specifies the font to use when writing text on the image.
property Font: TFont;
__property TFont Font;
Set Font to specify the font to use for writing text on the image. The value of Font is a T Font object. Set the properties of the T Font object to specify the font face, color, size, style, and any other aspects of the font.
The Canvas.Font property is only guaranteed to equal the Font property if you have an owner-drawn listbox (where you are expected to use the canvas). Even in that case, it is only guaranteed to equal the Font property once the first paint message is underway. If you use a canvas inside an ownerdraw event, everything should work as expected. Using the canvas for a reason outside the scope of its intended usage may give unpredictable results.
C++ Examples:
/* This example creates a rotated font and displays it on the form by assigning the handle of the rotated to the Form’s Canvas Font via the Font’s Handle property. Rotating fonts is a straightforward process, so long as the Windows Font Mapper can supply a rotated font based on the font you request. If you are using a TrueType font there is virtually no reason for failure. */ void __fastcall TForm1::Button1Click(TObject *Sender) { LOGFONT lf; // Windows native font structure Canvas->Brush->Style = bsClear; // set the brush style to transparent ZeroMemory(&lf, sizeof(LOGFONT)); lf.lfHeight = 20; lf.lfEscapement = 10 * 45; // degrees to rotate lf.lfOrientation = 10 * 45; lf.lfCharSet = DEFAULT_CHARSET; strcpy(lf.lfFaceName, "Tahoma"); Canvas->Font->Handle = CreateFontIndirect(&lf); Canvas->TextOut(10, 100, "Rotated text"); // output the rotated font }
Delphi Examples:
{ This example creates a rotated font and displays it on the form by assigning the handle of the rotated to the Form’s Canvas Font via the Font’s Handle property. Rotating fonts is a straightforward process, so long as the Windows Font Mapper can supply a rotated font based on the font you request. If you are using a TrueType font there is virtually no reason for failure. } procedure TForm1.Button1Click(Sender: TObject); var lf: LOGFONT; // Windows native font structure begin Canvas.Brush.Style := bsClear; // set the brush style to transparent FillChar(lf, SizeOf(lf), Byte(0)); lf.lfHeight := 20; lf.lfEscapement := 10 * 45; // degrees to rotate lf.lfOrientation := 10 * 45; lf.lfCharSet := DEFAULT_CHARSET; StrCopy(lf.lfFaceName, 'Tahoma'); Canvas.Font.Handle := CreateFontIndirect(lf); Canvas.TextOut(10, 100, 'Rotated text'); // output the rotated font end;
Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
|
What do you think about this topic? Send feedback!
|