Hinweis
Für den Zugriff auf diese Seite ist eine Autorisierung erforderlich. Sie können versuchen, sich anzumelden oder das Verzeichnis zu wechseln.
Für den Zugriff auf diese Seite ist eine Autorisierung erforderlich. Sie können versuchen, das Verzeichnis zu wechseln.
Erstellt ein GDI+-Icon aus dem angegebenen Windows-Handle für ein Symbol (HICON).
Namespace: System.Drawing
Assembly: System.Drawing (in system.drawing.dll)
Syntax
'Declaration
Public Shared Function FromHandle ( _
handle As IntPtr _
) As Icon
'Usage
Dim handle As IntPtr
Dim returnValue As Icon
returnValue = Icon.FromHandle(handle)
public static Icon FromHandle (
IntPtr handle
)
public:
static Icon^ FromHandle (
IntPtr handle
)
public static Icon FromHandle (
IntPtr handle
)
public static function FromHandle (
handle : IntPtr
) : Icon
Parameter
- handle
Ein Windows-Handle für ein Symbol.
Rückgabewert
Das Icon, das von dieser Methode erstellt wird.
Hinweise
Bei Verwendung dieser Methode müssen Sie das resultierende Symbol mithilfe der DestroyIcon-Methode in der Win32 API verwerfen, um die Freigabe der Ressourcen sicherzustellen.
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:
Erstellt eine Bitmap.
Zeichnet das Objekt auf dem Bildschirm.
Ruft ein Symbolhandle für die Bitmap ab.
Legt das Form.Icon-Attribut des Formulars auf ein Symbol fest, das anhand des Handles erstellt wurde.
Ruft die Win32 API-Funktion DestroyIcon auf, um Ressourcen freizugeben.
<System.Runtime.InteropServices.DllImportAttribute("user32.dll")> _
Private Shared Function DestroyIcon(ByVal handle _
As IntPtr) As Boolean
End Function
Private Sub GetHicon_Example(ByVal e As PaintEventArgs)
' Create a Bitmap object from an image file.
Dim myBitmap As New Bitmap("c:\FakePhoto.jpg")
' Draw myBitmap to the screen.
e.Graphics.DrawImage(myBitmap, 0, 0)
' Get an Hicon for myBitmap.
Dim HIcon As IntPtr = myBitmap.GetHicon()
' Create a new icon from the handle.
Dim newIcon as Icon = System.Drawing.Icon.FromHandle(HIcon)
' Set the form Icon attribute to the new icon.
Me.Icon = newIcon
' Destroy the icon, since the form creates its
' own copy of the icon.
DestroyIcon(newIcon.Handle)
End Sub
[System.Runtime.InteropServices.DllImport("user32.dll", CharSet=CharSet.Auto)]
extern static bool DestroyIcon(IntPtr handle);
private void GetHicon_Example(PaintEventArgs e)
{
// Create a Bitmap object from an image file.
Bitmap myBitmap = new Bitmap(@"c:\FakePhoto.jpg");
// Draw myBitmap to the screen.
e.Graphics.DrawImage(myBitmap, 0, 0);
// Get an Hicon for myBitmap.
IntPtr Hicon = myBitmap.GetHicon();
// Create a new icon from the handle.
Icon newIcon = Icon.FromHandle(Hicon);
// Set the form Icon attribute to the new icon.
this.Icon = newIcon;
// Destroy the Icon, since the form creates
// its own copy of the icon.
DestroyIcon(newIcon.Handle);
}
private:
[System::Runtime::InteropServices::DllImportAttribute("user32.dll",CharSet=CharSet::Auto)]
static bool DestroyIcon( IntPtr handle );
public:
[SecurityPermission(SecurityAction::Demand, Flags=SecurityPermissionFlag::UnmanagedCode)]
void GetHicon_Example( PaintEventArgs^ e )
{
// Create a Bitmap object from an image file.
Bitmap^ myBitmap = gcnew Bitmap( "c:\\FakePhoto.jpg" );
// Draw myBitmap to the screen.
e->Graphics->DrawImage( myBitmap, 0, 0 );
// Get an Hicon for myBitmap.
IntPtr Hicon = myBitmap->GetHicon();
// Create a new icon from the handle.
System::Drawing::Icon^ newIcon = ::Icon::FromHandle( Hicon );
// Set the form Icon attribute to the new icon.
this->Icon = newIcon;
// Destroy the Icon, since the form creates
// its own copy of the icon.
DestroyIcon( newIcon->Handle );
}
.NET Framework-Sicherheit
- SecurityPermission für den Zugriff auf nicht verwalteten Code. Zugehörige Enumeration: UnmanagedCode.
Plattformen
Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile für Pocket PC, Windows Mobile für Smartphone, 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
.NET Compact Framework
Unterstützt in: 2.0