Click here to Skip to main content
15,879,535 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am using SharpDevelop 3.2.1 to write a very simple VB program that runs in the System Tray by utilizing a notifyIcon component and a contextMenuStrip component. I am using a tutorial found at VisualBasicTutorials[^]as the basis for my code.

What I need to do is be able to change the icon shown in the system tray depending upon what subroutine is currently active.

I have a resource file called Resouces.resx to which I have added three icons.

Unfortunately, I cannot discover how to reference this resource file to be able to access the icons. This page[^] at msdn states that all you have to do is change the icon property with this:

VB
NotifyIcon1.Icon = My.Resouces.YourIcon


If I type this, as soon as I get to 'My.' The only options that come up are Application, Computer, Forms, User

If I ignore this and type in the line as suggested at MSDN, I get a compile error stating that Resources is not a member of My

I must be overlooking something, but what??
Posted
Updated 15-Aug-14 5:09am
v2

You are looking in wrong direction. This is not how .resx resources are designed. You can add resources at any level of you project structure, and the namespace will be different, because the code is automatically generated based with the namespace name built based on the base namespace of the application and this location.

So, getting a resource is way too simple. First thing to understand that a static property is generated for you. Create a resource file, add you icon to it. If is, by far, beneficial to have an icon in a separate file, not embed it in a resource. Even if you edited it in a resource, save it as a file and remove from resource. Add it using "Add existing file", say, "YourIcon.ico". Make sure the original icon is not a part of your project, to avoid duplicates. The add step will: 1) copy the file to some directory of your project (that's why you'll have to check for duplicates and avoid them), 2) add the file reference to the project file (and hence project structure, will show a node for it), 3) add a reference to the file to the resource file, 4) generate the code getting this this resource in a auto-generated file, which is shown in a structure of the project as a child node of the resource node.

The last item is the key one. Open this auto-generated file and take a look. You will find a static property with the name similar to the name of the file, in this case, YourIcon with appropriate type, such as Image or Icon. Just use this property directly in your code, using its fully-qualified name (you can add the using declaration to your file, perhaps alias.

If the type of the file is unknown to Visual Studio, the auto-generated property type will be byte[]; one of the way to use it would be putting the bytes a memory stream an reading the instance of the object from this stream.

I described the general approach you need to use in your cases. As to "My", this is something more specific. If you need to understand what is that, please read:
http://msdn.microsoft.com/en-us/library/bb531245.aspx[^],
http://msdn.microsoft.com/en-us/library/8ffec36z.aspx[^],
http://msdn.microsoft.com/en-us/library/6wkcc526.aspx[^].

—SA
 
Share this answer
 
v2
Thanks Sergey for your in-depth answer... you make some valid points and it just reinforces how much I still have to learn :).

I was able to find a webpage at the SharpDevelop section of github which clarified the matter. I thought I'd put a link to it here for others who have the same problem.

LINK https://github.com/icsharpcode/SharpDevelop/wiki/Using-Resources[^]

Specifically this info solved my problem:

You can tell SharpDevelop to automatically generate a class that makes accessing resources stored in .resx files easier by selecting the .resx file in the project browser, then opening the properties window and setting "Custom Tool" to "ResXFileCodeGenerator". Then right click the .resx file in the project browser and choose "Execute custom tool". This will generate a ".Designer.cs" file for the resource file that contains a class for easy access to the resources. The class will automatically be regenerated whenever you change the .resx file inside SharpDevelop. You can access the resources using "ResourceFile.Test_dat" / "ResourceFile.Image".
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900