Getting Icon from ResourceStream

2019-05-16 08:51发布

I have a Icon.ico and in the Properties the Build Action is "Resource"...

I want to load that Icon in the Application..

I did something like this:

Icon theIcon = new Icon(System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream("MyNameSpace.Icon.ico"));

that didnt worked (it says "Value of 'null' is not valid for 'stream'.")

What can I do?

1条回答
Deceive 欺骗
2楼-- · 2019-05-16 09:25

try using Application.GetResourceStream method

using(Stream stream = Application.GetResourceStream(new Uri("/MyNameSpace.ico")).Stream)
{
    Icon myIcon = new System.Drawing.Icon(stream);
}

more information from MSDN

查看更多
登录 后发表回答