Font.ToHfont Metoda
Definice
Důležité
Některé informace platí pro předběžně vydaný produkt, který se může zásadně změnit, než ho výrobce nebo autor vydá. Microsoft neposkytuje žádné záruky, výslovné ani předpokládané, týkající se zde uváděných informací.
Vrátí popisovač pro tento Font.
public:
IntPtr ToHfont();
public IntPtr ToHfont ();
member this.ToHfont : unit -> nativeint
Public Function ToHfont () As IntPtr
Návraty
nativeint
Popisovač systému Windows pro tento Font.
Výjimky
Operace nebyla úspěšná.
Příklady
Následující příklad kódu vytvoří Font a pak získá popisovač pro tento Fontkód . Příklad je navržený pro použití s model Windows Forms a vyžaduje PaintEventArgse
, což je parametr obslužné rutiny Paint události.
//Reference the GDI DeleteObject method.
public:
[System::Runtime::InteropServices::DllImport("GDI32.dll")]
static bool DeleteObject( IntPtr objectHandle );
void ToHfont_Example( PaintEventArgs^ /*e*/ )
{
// Create a Font object.
System::Drawing::Font^ myFont = gcnew System::Drawing::Font( "Arial",16 );
// Get a handle to the Font object.
IntPtr hFont = myFont->ToHfont();
// Display a message box with the value of hFont.
MessageBox::Show( hFont.ToString() );
//Dispose of the hFont.
DeleteObject( hFont );
}
//Reference the GDI DeleteObject method.
[System.Runtime.InteropServices.DllImport("GDI32.dll")]
public static extern bool DeleteObject(IntPtr objectHandle);
public void ToHfont_Example(PaintEventArgs e)
{
// Create a Font object.
Font myFont = new Font("Arial", 16);
// Get a handle to the Font object.
IntPtr hFont = myFont.ToHfont();
// Display a message box with the value of hFont.
MessageBox.Show(hFont.ToString());
//Dispose of the hFont.
DeleteObject(hFont);
}
' Reference the DeleteObject method in the GDI library.
<System.Runtime.InteropServices.DllImportAttribute("GDI32.DLL")> _
Private Shared Function DeleteObject(ByVal objectHandle As IntPtr) As Boolean
End Function
Public Sub ToHfont_Example(ByVal e As PaintEventArgs)
' Create a Font object.
Dim myFont As New Font("Arial", 16)
' Get a handle to the Font object.
Dim hFont As IntPtr = myFont.ToHfont()
' Display a message box with the value of hFont.
MessageBox.Show(hFont.ToString())
' Dispose of the hFont.
DeleteObject(hFont)
End Sub
Poznámky
Při použití této metody musíte odstranit výslednou Hfont
metodu pomocí metody GDI DeleteObject
, aby se zajistilo uvolnění prostředků.
Platí pro
Váš názor
https://aka.ms/ContentUserFeedback.
Připravujeme: V průběhu roku 2024 budeme postupně vyřazovat problémy z GitHub coby mechanismus zpětné vazby pro obsah a nahrazovat ho novým systémem zpětné vazby. Další informace naleznete v tématu:Odeslat a zobrazit názory pro