Font.FromHfont(IntPtr) Yöntem

Tanım

Belirtilen Windows tanıtıcısından bir Font oluşturur.

C#
public static System.Drawing.Font FromHfont (IntPtr hfont);

Parametreler

hfont
IntPtr

GDI yazı tipinin Windows tanıtıcısı.

Döndürülenler

Bu yöntemin oluşturduğu Font.

Özel durumlar

hfont TrueType yazı tipi olmayan bir nesneyi gösterir.

Örnekler

Aşağıdaki kod örneği Windows Forms ile kullanılmak üzere tasarlanmıştır ve Paint olay işleyicisinin bir parametresi olan PaintEventArgsegerektirir. Kod aşağıdaki eylemleri gerçekleştirir:

  • GDI yazı tipinin tutamacını alır.

  • Bu tanıtıcıdan bir Font oluşturur.

  • Yeni Fontkullanarak ekrana metin çizer.

C#
[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);
}

Şunlara uygulanır

Ürün Sürümler
.NET 6, 7, 8, 9
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9