Icon.ExtractAssociatedIcon(String) 方法

定义

返回指定文件中包含的图像的图标表示形式。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

参数

filePath
String

包含图像的文件的路径。The path to the file that contains an image.

返回

Icon

指定文件中包含的图像的 Icon 表示形式。The Icon representation of the image that is contained in the specified file.

例外

filePath 不指示有效文件。The filePath does not indicate a valid file.

- 或 --or- filePath 指示通用命名约定 (UNC) 路径。The filePath indicates a Universal Naming Convention (UNC) path.

示例

下面的代码示例演示如何使用 ExtractAssociatedIcon 方法。The following code example demonstrates how to use the ExtractAssociatedIcon method. 若要运行此示例,请将代码粘贴到 Windows 窗体中,并 ExtractAssociatedIconEx 从窗体的构造函数或 Load 事件处理程序调用。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

注解

相对路径假定为相对于当前工作目录。A relative path is assumed to be relative to the current working directory.

ExtractAssociatedIcon 与位图一起使用时,如果运行应用程序的系统的注册表设置导致位图文件显示为缩略图,则可能会返回缩略图,而不是图标。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.

适用于