Bitmap.GetHicon-Methode
Gibt das Handle für ein Symbol zurück.
Namespace: System.Drawing
Assembly: System.Drawing (in system.drawing.dll)
Syntax
'Declaration
Public Function GetHicon As IntPtr
'Usage
Dim instance As Bitmap
Dim returnValue As IntPtr
returnValue = instance.GetHicon
public IntPtr GetHicon ()
public:
IntPtr GetHicon ()
public IntPtr GetHicon ()
public function GetHicon () : IntPtr
Rückgabewert
Ein Windows-Handle für ein Symbol mit einem Bild, das mit der Bitmap übereinstimmt.
Ausnahmen
Ausnahmetyp | Bedingung |
---|---|
Der Vorgang ist fehlgeschlagen. |
Hinweise
Ein anhand des Handles erstelltes Symbol weist zunächst dieselbe Größe wie die ursprüngliche Bitmap auf.
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 einen 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.
<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 Aufruf von nicht verwaltetem Code. Zugehörige Enumeration: UnmanagedCode
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