开发者

Load application icon through resource

Here's what I've done:

I created a resource.resx file using my IDE (SharpDevelop) and added an logo.ico to it. The resource.resx file looks something like this:

<data name="logo" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
    <value>
        AAABAAEAEBAAAAEAIABoBAAAFgAAACgAAAAQAAAAIAAA... (etc etc)

Then I used ResGen.exe to compile this resource.resx into a valid resource.resources file.

resgen.exe resource.resx resource.resources

Using the command line 开发者_运维问答JScript.NET compiler I compiled everything and included my resource.resources which has my logo file.

jsc /res:resource.resources /out:app.exe /reference:UI.dll,Remote.dll app.cs

Now I want to access this logo file from withing my code, so I've got this:

System.Reflection.Assembly assembly = System.Reflection.Assembly.GetExecutingAssembly();
System.Drawing.Icon icon = new System.Drawing.Icon(assembly.GetManifestResourceStream("resource.resources.logo"));

However I get a runtime Exception for GetManifestResourceStream which is null.

I suppose this is a namespace issue so I tried accessing the resource file only with GetManifestResourceStream("resource.resources") but I get this other Exception:

Argument 'picture' must be a picture that can be used as a Icon.

Any ideas would be greatly appreciated, thanks!


It is complaining about the file format, it doesn't recognize it as an icon. I can't tell from your snippet, not enough of the base64 encoded value is visible.

I have to say, if this IDE is making you write code like this then it is not helping you. Storing icons in the resources is utterly trivial in Visual Studio, there is no need to write any code at all. The Express edition has the same price.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜