Прочетете на английски Редактиране

Споделяне чрез


Bitmap.FromHicon(IntPtr) Method

Definition

Creates a Bitmap from a Windows handle to an icon.

C#
public static System.Drawing.Bitmap FromHicon(IntPtr hicon);

Parameters

hicon
IntPtr

A handle to an icon.

Returns

The Bitmap that this method creates.

Examples

The following code example is designed for use with Windows Forms, and it requires PaintEventArgs e, which is a parameter of the Paint event handler. The code performs the following actions:

  • Gets the handle to an existing icon image.

  • Creates a Bitmap from the handle.

  • Draws the Bitmap to the screen.

C#
[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);
}

Applies to

Продукт Версии
.NET 8 (package-provided), 9 (package-provided), 10 (package-provided)
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0 (package-provided)
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9, 10