Redigeeri

Jagamisviis:


Icon.ExtractAssociatedIcon(String) Method

Definition

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

public:
 static System::Drawing::Icon ^ ExtractAssociatedIcon(System::String ^ filePath);
public static System.Drawing.Icon? ExtractAssociatedIcon (string filePath);
public static System.Drawing.Icon ExtractAssociatedIcon (string filePath);
static member ExtractAssociatedIcon : string -> System.Drawing.Icon
Public Shared Function ExtractAssociatedIcon (filePath As String) As Icon

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.

private void ExtractAssociatedIconEx()
{
    Icon ico =
        Icon.ExtractAssociatedIcon(@"C:\WINDOWS\system32\notepad.exe");
    this.Icon = ico;
}
Private Sub ExtractAssociatedIconEx()
    Dim ico As Icon = Icon.ExtractAssociatedIcon("C:\WINDOWS\system32\notepad.exe")
    Me.Icon = ico

End Sub

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