0

I'm a complete newbie at C# I'm using Notepad++ for coding with CS-Script plugin for notepad++. I've developed a little script in it.

In such script I use a traybar icon that I made myself and I included a reference to it in the script with the following row of code

trayIcon.Icon = new Icon("icon.ico");

That works almost as I need... but look at the following image for clarification:

Binary with the embedded Icon file

Than I prepare the exe for distribution with the CS-Script command and it works beautifully. The problem is that the compiling procedure doesn't include the icon into the binary file so I must include by hands the icon file it self into the same directory of the binary file: in fact the exe file generated hangs with an error if icon file isn't included.

Question:

Is there a way to solve the problem and make the "binary package" all in one file with both the executable part and the ico resource file altogether?

Constraints:

I know I can create a rar, zip, or compressed exe (self-extracting file) but I don't mean that: I want 1 exe file with the icon in it that can be executed and moved stand alone. In other word the icon has to be embedded into the stand alone exe because it is the exe file icon itself and the icon for the windows traybar.

Screenshot of CS-Script in Notepad++

willy wonka
  • 1,440
  • 1
  • 18
  • 31
  • Please try to use ```css_resource``` directive to include your icon to the binary. http://www.csscript.net/help/Using_Resources.html – Uladzimir Palekh Apr 04 '17 at 23:47
  • @UladzimirPalekh Tnx for response: I've inserted the following code **//css_resource icon.ico;** and the file now is included, (the exe is bigger than before) but still it is not used as exe icon and the exe still hangs if the icon isn't into the directory. – willy wonka Apr 05 '17 at 02:38
  • Link in my previous comment contains usage sample (last snippet with ```ResourceManager```). Also you can check this question for more information: https://stackoverflow.com/questions/13592150/load-image-from-resources – Uladzimir Palekh Apr 05 '17 at 07:16
  • @UladzimirPalekh I had a look on the links you posted and I made some modifications to my code but still not working: I'm getting errors: error CS0103: The name 'Resources' doesn't exist in the current context. e:\C# Scripts\ScreenShots.cs(77,20): error CS0029: Impossible to convert implicit the type System.Drawing.Bitmap' in 'System.Drawing.Icon' error CS0103: The name 'Assembly' non esiste nel contesto corrente. e:\C# Scripts\ScreenShots.cs(71,19): error CS1061: – willy wonka Apr 05 '17 at 19:28
  • 'System.Resources.ResourceManager' doesn't contain a definition of 'ResourceManager' and it was not found any method of extension 'ResourceManager'. **I've translated the errors texts from my language that is not English** I hope this helps Tnx – willy wonka Apr 05 '17 at 19:29

1 Answers1

1

I have found this way to get Icon from the embedded resources in the CS-Script compiled binary. Icon file name is alpha.ico.

Please pay attention to the using section.

//css_resource alpha.ico

using System;
using System.Drawing;
using System.Windows.Forms;
using System.Reflection;

class Script
{
    [STAThread]
    static public void Main(string[] args)
    {
        var assembly = Assembly.GetExecutingAssembly();

        using (var stream = assembly.GetManifestResourceStream("alpha.ico"))
        {
            var icon = new Icon(stream);
        }
    }
}
Uladzimir Palekh
  • 1,846
  • 13
  • 16