Font.FromHfont(IntPtr) Metoda

Definicja

Tworzy obiekt Font na podstawie określonego dojścia systemu Windows.

public:
 static System::Drawing::Font ^ FromHfont(IntPtr hfont);
public static System.Drawing.Font FromHfont (IntPtr hfont);
static member FromHfont : nativeint -> System.Drawing.Font
Public Shared Function FromHfont (hfont As IntPtr) As Font

Parametry

hfont
IntPtr

nativeint

Uchwyt systemu Windows dla czcionki GDI.

Zwraca

Ta Font metoda tworzy.

Wyjątki

hfont wskazuje obiekt, który nie jest czcionką TrueType.

Przykłady

Poniższy przykład kodu jest przeznaczony do użycia z Windows Forms i wymaga PaintEventArgseparametru Paint programu obsługi zdarzeń. Kod wykonuje następujące akcje:

  • Pobiera uchwyt do czcionki GDI.

  • Tworzy obiekt Font na podstawie tego uchwytu.

  • Rysuje tekst na ekranie przy użyciu nowego Fontelementu .

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( 17 );

      // 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 );
   }
[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);
}
<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(17)

    ' 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

Dotyczy