嵌入式资源文件的路径

gya*_*guy 17 .net c#

我的资源文件中有一个图标,我想引用它.

这是需要该图标文件路径的代码:

IWshRuntimeLibrary.IWshShortcut MyShortcut  ;
MyShortcut =   (IWshRuntimeLibrary.IWshShortcut)WshShell.CreateShortcut(Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory) + @"\PerfectUpload.lnk");
MyShortcut.IconLocation = //path to icons path . Works if set to @"c:/icon.ico" 
Run Code Online (Sandbox Code Playgroud)

我没有外部图标文件,而是希望它找到嵌入式图标文件.就像是

MyShortcut.IconLocation  = Path.GetFullPath(global::perfectupload.Properties.Resources.finish_perfect1.ToString()) ;
Run Code Online (Sandbox Code Playgroud)

这可能吗 ?如果是这样的话?

谢谢

Sha*_*ain 3

我认为它会在某些方面对您有所帮助...

//Get the assembly.
System.Reflection.Assembly CurrAssembly = System.Reflection.Assembly.LoadFrom(System.Windows.Forms.Application.ExecutablePath);

//Gets the image from Images Folder.
System.IO.Stream stream = CurrAssembly.GetManifestResourceStream("ImageURL");

if (null != stream)
{
    //Fetch image from stream.
    MyShortcut.IconLocation = System.Drawing.Image.FromStream(stream);
}
Run Code Online (Sandbox Code Playgroud)

  • 这不起作用,因为 IWshShortcut.IconLocation 是一个字符串,而 Image.FromStream() 是一个图像。您必须将图像写入文件,并将 IconLocation 指向该文件。 (6认同)