Freigeben über


Font.FromHfont-Methode

Erstellt einen Font aus dem angegebenen Windows-Handle.

Namespace: System.Drawing
Assembly: System.Drawing (in system.drawing.dll)

Syntax

'Declaration
Public Shared Function FromHfont ( _
    hfont As IntPtr _
) As Font
'Usage
Dim hfont As IntPtr
Dim returnValue As Font

returnValue = Font.FromHfont(hfont)
public static Font FromHfont (
    IntPtr hfont
)
public:
static Font^ FromHfont (
    IntPtr hfont
)
public static Font FromHfont (
    IntPtr hfont
)
public static function FromHfont (
    hfont : IntPtr
) : Font

Parameter

  • hfont
    Ein Windows-Handle für eine GDI-Schriftart.

Rückgabewert

Der von dieser Methode erstellte Font.

Beispiel

Das folgende Codebeispiel ist für die Verwendung mit Windows Forms vorgesehen und erfordert PaintEventArgse, wobei es sich um einen Parameter des Paint-Ereignishandlers handelt. Der Code führt die folgenden Aktionen aus:

  • Ruft ein Handle für eine GDI-Schriftart ab.

  • Erstellt einen Font aus diesem Handle.

  • Zeichnet mit dem neuen Font-Objekt Text auf dem Bildschirm.

<System.Runtime.InteropServices.DllImportAttribute("GDI32.DLL")> _
Private Shared Function GetStockObject(ByVal fnObject As Integer) As IntPtr
End Function
Public Sub FromHfont_Example(ByVal e As PaintEventArgs)

    ' Get a handle for a GDI font.
    Dim hFont As IntPtr = GetStockObject(0)

    ' Create a Font object from hFont.
    Dim hfontFont As Font = Font.FromHfont(hFont)

    ' Use hfontFont to draw text to the screen.
    e.Graphics.DrawString("This font is from a GDI HFONT", hfontFont, _
    Brushes.Black, 0, 0)
End Sub
[System.Runtime.InteropServices.DllImportAttribute("gdi32.dll")]
private static extern IntPtr GetStockObject(int fnObject);
public void FromHfont_Example(PaintEventArgs e)
{
             
    // Get a handle for a GDI font.
    IntPtr hFont = GetStockObject(0);
             
    // Create a Font object from hFont.
    Font hfontFont = Font.FromHfont(hFont);
             
    // Use hfontFont to draw text to the screen.
    e.Graphics.DrawString(
        "This font is from a GDI HFONT", hfontFont,Brushes.Black, 
        0, 0);
       
        
        
        
}
private:
   [System::Runtime::InteropServices::DllImportAttribute("gdi32.dll")]
   static IntPtr GetStockObject( int fnObject );

public:
   void FromHfont_Example( PaintEventArgs^ e )
   {
      // Get a handle for a GDI font.
      IntPtr hFont = GetStockObject( 0 );

      // Create a Font object from hFont.
      System::Drawing::Font^ hfontFont = System::Drawing::Font::FromHfont( hFont );

      // Use hfontFont to draw text to the screen.
      e->Graphics->DrawString( "This font is from a GDI HFONT", hfontFont, Brushes::Black, 0, 0 );
   }
/** @attribute System.Runtime.InteropServices.DllImportAttribute(
    "gdi32.dll")
 */
private static native IntPtr GetStockObject(int fnObject);

public void FromHfont_Example(PaintEventArgs e)
{
    // Get a handle for a GDI font.
    IntPtr hFont = GetStockObject(0);

    // Create a Font object from hFont.
    Font hfontFont = Font.FromHfont(hFont);

    // Use hfontFont to draw text to the screen.
    e.get_Graphics().DrawString("This font is from a GDI HFONT", hfontFont,
        Brushes.get_Black(), 0, 0);
} //FromHfont_Example

.NET Framework-Sicherheit

Plattformen

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile für Pocket PC, Windows Mobile für Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

.NET Framework unterstützt nicht alle Versionen sämtlicher Plattformen. Eine Liste der unterstützten Versionen finden Sie unter Systemanforderungen.

Versionsinformationen

.NET Framework

Unterstützt in: 2.0, 1.1, 1.0

.NET Compact Framework

Unterstützt in: 2.0

Siehe auch

Referenz

Font-Klasse
Font-Member
System.Drawing-Namespace