Freigeben über


Bitmap.FromHicon-Methode

Erstellt eine Bitmap aus einem Windows-Handle für ein Symbol.

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

Syntax

'Declaration
Public Shared Function FromHicon ( _
    hicon As IntPtr _
) As Bitmap
'Usage
Dim hicon As IntPtr
Dim returnValue As Bitmap

returnValue = Bitmap.FromHicon(hicon)
public static Bitmap FromHicon (
    IntPtr hicon
)
public:
static Bitmap^ FromHicon (
    IntPtr hicon
)
public static Bitmap FromHicon (
    IntPtr hicon
)
public static function FromHicon (
    hicon : IntPtr
) : Bitmap

Parameter

  • hicon
    Ein Handle für ein Symbol.

Rückgabewert

Die neue Bitmap, die von dieser Methode erstellt wird.

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 das Handle für ein vorhandenes Symbolbild ab.

  • Erstellt eine Bitmap aus dem Handle.

  • Zeichnet die Bitmap auf dem Bildschirm.

<System.Runtime.InteropServices.DllImportAttribute("user32.dll")> _
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

Public 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
[System.Runtime.InteropServices.DllImportAttribute("user32.dll")]
private static extern IntPtr LoadImage(int Hinstance,
    string name, int type, int width, int height, int load);

public 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);
}
private:
   [System::Runtime::InteropServices::DllImportAttribute("user32.dll")]
   static IntPtr LoadImage( int Hinstance, String^ name, int type, int width, int height, int load );

public:
   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 );
   }

.NET Framework-Sicherheit

Plattformen

Windows 98, Windows 2000 SP4, Windows Millennium Edition, 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

Siehe auch

Referenz

Bitmap-Klasse
Bitmap-Member
System.Drawing-Namespace