RAD Studio VCL Reference
ContentsIndex
PreviousUpNext
TFont.Handle Property

Provides access to the handle of a system font.

Pascal
property Handle: HFont;
C++
__property HFont Handle;

The Handle property indicates the Windows GDI font object handle. 

Use Handle as a parameter when calling Windows API functions that require a font handle. Set Handle to make the TFont object represent the Windows font indicated by the font handle. Setting Handle releases the current Windows font resource.

Note: When possible, change a font by setting the other properties of TFont rather than using the Handle property. Setting Handle does not reset the properties that describe the font. However, an OnChange event does occur when Handle is set directly by an application.
 

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) 2008 CodeGear(TM). All Rights Reserved.
What do you think about this topic? Send feedback!