Olvasás angol nyelven Szerkesztés

Megosztás a következőn keresztül:


Icon.ExtractAssociatedIcon(String) Method

Definition

Returns an icon representation of an image that is contained in the specified file.

C#
public static System.Drawing.Icon? ExtractAssociatedIcon(string filePath);
C#
public static System.Drawing.Icon ExtractAssociatedIcon(string filePath);

Parameters

filePath
String

The path to the file that contains an image.

Returns

The Icon representation of the image that is contained in the specified file.

Exceptions

The filePath does not indicate a valid file.

-or-

The filePath indicates a Universal Naming Convention (UNC) path.

Examples

The following code example demonstrates how to use the ExtractAssociatedIcon method. To run this example, paste the code into a Windows Form and call ExtractAssociatedIconEx from the form's constructor or Load event handler.

C#
private void ExtractAssociatedIconEx()
{
    Icon ico =
        Icon.ExtractAssociatedIcon(@"C:\WINDOWS\system32\notepad.exe");
    this.Icon = ico;
}

Remarks

A relative path is assumed to be relative to the current working directory.

When ExtractAssociatedIcon is used with bitmaps, a thumbnail image may be returned instead of an icon if the system that is running the application has a registry setting that causes bitmap files to be shown as thumbnail images.

Applies to

Termék Verziók
.NET 8 (package-provided), 9 (package-provided), 10 (package-provided)
.NET Framework 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