Bitmap.FromHicon(IntPtr) Méthode
Définition
Important
Certaines informations portent sur la préversion du produit qui est susceptible d’être en grande partie modifiée avant sa publication. Microsoft exclut toute garantie, expresse ou implicite, concernant les informations fournies ici.
Crée un Bitmap à partir du handle Windows d'une icône.
public:
static System::Drawing::Bitmap ^ FromHicon(IntPtr hicon);
public static System.Drawing.Bitmap FromHicon (IntPtr hicon);
static member FromHicon : nativeint -> System.Drawing.Bitmap
Public Shared Function FromHicon (hicon As IntPtr) As Bitmap
Paramètres
- hicon
-
IntPtr
nativeint
Handle d'une icône.
Retours
Bitmap créé par cette méthode.
Exemples
L’exemple de code suivant est conçu pour être utilisé avec Windows Forms et nécessite PaintEventArgse
, qui est un paramètre du Paint gestionnaire d’événements. Le code effectue les actions suivantes :
Obtient le handle d’une image d’icône existante.
Crée un Bitmap à partir du handle.
Dessine le Bitmap vers l’écran.
private:
[System::Runtime::InteropServices::DllImportAttribute("user32.dll", CharSet = CharSet::Unicode)]
static IntPtr LoadImage( int Hinstance, String^ name, int type, int width, int height, int load );
private:
void Hicon_Example( PaintEventArgs^ e )
{
// Get a handle to an icon.
IntPtr Hicon = LoadImage( 0, "smile.ico", 1, 0, 0, 16 );
// Create a Bitmap object from the icon handle.
Bitmap^ iconBitmap = Bitmap::FromHicon( Hicon );
// Draw the Bitmap object to the screen.
e->Graphics->DrawImage( iconBitmap, 0, 0 );
}
[System.Runtime.InteropServices.DllImportAttribute("user32.dll", CharSet = CharSet.Unicode)]
private static extern IntPtr LoadImage(int Hinstance,
string name, int type, int width, int height, int load);
private void Hicon_Example(PaintEventArgs e)
{
// Get a handle to an icon.
IntPtr Hicon = LoadImage(0, "smile.ico", 1, 0, 0, 16);
// Create a Bitmap object from the icon handle.
Bitmap iconBitmap = Bitmap.FromHicon(Hicon);
// Draw the Bitmap object to the screen.
e.Graphics.DrawImage(iconBitmap, 0, 0);
}
<System.Runtime.InteropServices.DllImportAttribute("user32.dll", CharSet:=CharSet.Unicode)> _
Private Shared Function LoadImage(ByVal Hinstance As Integer, ByVal name As String, ByVal type As Integer, ByVal width As Integer, ByVal height As Integer, ByVal load As Integer) As IntPtr
End Function
Private Sub HICON_Example(ByVal e As PaintEventArgs)
' Get a handle to an icon.
Dim Hicon As IntPtr = LoadImage(0, "smile.ico", 1, 0, 0, 16)
' Create a Bitmap object from the icon handle.
Dim iconBitmap As Bitmap = Bitmap.FromHicon(Hicon)
' Draw the Bitmap object to the screen.
e.Graphics.DrawImage(iconBitmap, 0, 0)
End Sub
S’applique à
Commentaires
https://aka.ms/ContentUserFeedback.
Bientôt disponible : Tout au long de 2024, nous allons supprimer progressivement GitHub Issues comme mécanisme de commentaires pour le contenu et le remplacer par un nouveau système de commentaires. Pour plus d’informations, consultezEnvoyer et afficher des commentaires pour