Help with Icons

Please support our C# advertiser: Intel Parallel Studio Home
Reply

Join Date: Jul 2005
Posts: 3
Reputation: HLD77 is an unknown quantity at this point 
Solved Threads: 0
HLD77 HLD77 is offline Offline
Newbie Poster

Help with Icons

 
0
  #1
Jul 27th, 2005
I am trying to change existing icons on a toolbar. The icons are placed under "img" directory. When I replace an old icon with a new one and build\start my project, I don't see the new icon. Can somebody let me know what am I doing wrong ?

Thanks a lot!
Reply With Quote Quick reply to this message  
Join Date: Jul 2005
Posts: 17
Reputation: cambia is an unknown quantity at this point 
Solved Threads: 3
cambia's Avatar
cambia cambia is offline Offline
Newbie Poster

Re: Help with Icons

 
0
  #2
Jul 28th, 2005
Originally Posted by HLD77
I am trying to change existing icons on a toolbar. ... When I replace an old icon with a new one and build\start my project, I don't see the new icon.
Hi HLD77,

I had this problem for a long time before I discovered what was going on. The Toolbar icons are all loaded in an ImageList control. The ImageList control is associated with the Toolbar to provide the various icons for your buttons.

The ImageList loads the icons by making a copy, (as a resource I believe, in your project) the first time you add the icon to the ImageList. The image on disk then no longer matters to the ImageList. To update the Toolbar, you must update the ImageList by deleting the old image and uploading the new one. When you set focus back to the Toolbar you should see the new icon on the toolbar. When re-loading the icon, you may need to move it to the right index position. There may also be some issues if your filename is exactly the same. If this happens, delete the icon, click on the design surface to update the toolbar, then re-upload the new icon. Should work.

It may seem annoying to have to update your icons all the time, but once you understand it, it's no big deal and it's nice not to have to bother with manually managing the icon resource yourself.

Cheers,
Steve
Reply With Quote Quick reply to this message  
Join Date: Jul 2005
Posts: 3
Reputation: HLD77 is an unknown quantity at this point 
Solved Threads: 0
HLD77 HLD77 is offline Offline
Newbie Poster

Re: Help with Icons

 
0
  #3
Jul 28th, 2005
Thanks Steve. Unfortunately I don't see icons in the toolbar in design view and hence I cannot update\delete the icons.

I am making changes to existing code and it's kind of hard to figure out which .resx file has these icon information. When I tried to edit the .resx file that is most likely to have this information in Resurce editor, I received "No resources to load in this file" error. Below is the code in case someone can figure out what's going on. Thanks!


try
{
this.ExecutingAssembly = System.Reflection.Assembly.GetExecutingAssembly();
this.FormResources = new System.Resources.ResourceManager( "MyApp.MyAppForm", this.ExecutingAssembly );

Icon ic1 = (System.Drawing.Icon) this.FormResources.GetObject ("connect.ico");
Icon ic2 = (System.Drawing.Icon) this.FormResources.GetObject ("disconnect.ico");

ImageList imglist = new ImageList();
imglist.Images.Add(ic1);
imglist.Images.Add(ic2);

this.toolBar.ImageList = imglist;
}


catch(Exception ex)
{
MessageBox.Show (ex.Message + ex.StackTrace);
}

for (int iToolButt = 0; iToolButt < toolbarText.Length; iToolButt ++)
{
ToolBarButton tButt = new ToolBarButton();
tButt.ImageIndex = iToolButt;
this.toolBar.Buttons.Add(tButt);
}
Reply With Quote Quick reply to this message  
Join Date: Jul 2005
Posts: 17
Reputation: cambia is an unknown quantity at this point 
Solved Threads: 3
cambia's Avatar
cambia cambia is offline Offline
Newbie Poster

Re: Help with Icons

 
0
  #4
Jul 29th, 2005
Well, looks like it's time to go into full on debug mode. :eek:

First you'll need to determine whether the resources are actually getting loaded. Add some code to print out all the names in the resource manifest. The following should get you started. Just loop over and print.

  1. string[] resources = Assembly.GetExecutingAssembly().GetManifestResourceNames();

If you see the icon names, then you just have to figure out how to access the resource. The following might help:

  1. strm = Assembly.GetExecutingAssembly().GetManifestResourceStream(fullResourceName);
  2. icon = new Icon(strm);

Also, Ensure that your icons are being loaded as application resources. Right-click the icon file in Solution Explorer, select properties, and then specify the Build Action as embedded resource. If you don't, the icon will not be an application resource and cannot be accessed the way your code is doing it.

Cheers,
Steve
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC