how to change icons
-
Hy everyone! I want to change the icon of my WindowsForms Window and my notifyicon depending on the system state meaning, if the apllication is able to do a special kind of work then the icon is style A, if it fails then it changes to style B. If the user tries again and this time it works then the icon changes back to style A. In general: application works correctly => icon A application fails => icon B application works correctly (after having failed before) => icon changes from B to A. Well how do I realize this in my application? I know there is something like notify.Icon but there it says for example
this.tbiNameKeyService.Icon = ((System.Drawing.Icon)(resources.GetObject("tbiNameKeyService.Icon")));
at the moment I have no idea 1) where the application chooses to use my icon I assigned in the properties 2) how to change/switch the icon depending on the state (ok/failure) because of 1) I mean I could have tried to use an absolute link to the file but then my application is fixed to this configuration. But I want it not to be absolute! Meaning I do want to being able to "port" it to another computer. Thanks! Stephan. -
Hy everyone! I want to change the icon of my WindowsForms Window and my notifyicon depending on the system state meaning, if the apllication is able to do a special kind of work then the icon is style A, if it fails then it changes to style B. If the user tries again and this time it works then the icon changes back to style A. In general: application works correctly => icon A application fails => icon B application works correctly (after having failed before) => icon changes from B to A. Well how do I realize this in my application? I know there is something like notify.Icon but there it says for example
this.tbiNameKeyService.Icon = ((System.Drawing.Icon)(resources.GetObject("tbiNameKeyService.Icon")));
at the moment I have no idea 1) where the application chooses to use my icon I assigned in the properties 2) how to change/switch the icon depending on the state (ok/failure) because of 1) I mean I could have tried to use an absolute link to the file but then my application is fixed to this configuration. But I want it not to be absolute! Meaning I do want to being able to "port" it to another computer. Thanks! Stephan.Basically you will want a way to query the status of your application, you could use a timer if needed, however when the status changes to whatever you specify, simply change the icon of your application. You could store the icons in a resource file, are you asking how you extract it? - Nick Parker
My Blog | My Articles -
Basically you will want a way to query the status of your application, you could use a timer if needed, however when the status changes to whatever you specify, simply change the icon of your application. You could store the icons in a resource file, are you asking how you extract it? - Nick Parker
My Blog | My Articlesif you mean the following by "query the status of my application" then you are right: it should do the following try { //do something //displayed icon is ok icon set ok icon } catch { // catch error // displayed icon is failed icon set failed icon } above is an example for what I want to do. Well this means I would have to "switch" the icon (see pseudocode above). Well change the icon? uhm, that's what I do not know how to do! Could you please post a sample how to do this or post a reference where it is described how to do so. I do know how to set the icon by
notify1.Icon=new Icon("myicon.ico");
but what do I have to do in the example above? At the moment I addednotify1.Icon=new Icon("myokicon.ico");
to the try section andnotify1.Icon=new Icon("myfailicon.ico");
to the catch section. Well the first time it works, but when I do want to do the next switch then it crashes. Meaning I am only able to donotify1.Icon=new Icon("myicon.ico";
once and never again. But what do I have to do to change this as often as I want it to change? So once again I would ask you to please let me know of a sample how to manage this problem or a link to a reference which describes how to manage this. Thanks! Stephan. -
if you mean the following by "query the status of my application" then you are right: it should do the following try { //do something //displayed icon is ok icon set ok icon } catch { // catch error // displayed icon is failed icon set failed icon } above is an example for what I want to do. Well this means I would have to "switch" the icon (see pseudocode above). Well change the icon? uhm, that's what I do not know how to do! Could you please post a sample how to do this or post a reference where it is described how to do so. I do know how to set the icon by
notify1.Icon=new Icon("myicon.ico");
but what do I have to do in the example above? At the moment I addednotify1.Icon=new Icon("myokicon.ico");
to the try section andnotify1.Icon=new Icon("myfailicon.ico");
to the catch section. Well the first time it works, but when I do want to do the next switch then it crashes. Meaning I am only able to donotify1.Icon=new Icon("myicon.ico";
once and never again. But what do I have to do to change this as often as I want it to change? So once again I would ask you to please let me know of a sample how to manage this problem or a link to a reference which describes how to manage this. Thanks! Stephan.I guess I just did it, well have to do some further testing! What I did is the following: first defining my icons
Icon iok=new Icon("myokicon.ico"); Icon ifail=new Icon("myfailicon.ico");
then I do just assign the icons designed above to the icons I do want to change. (Meaning when I do want the OK then I do assign this one, when I do want the failed then I do assign the failed. It's quit simple when you know how to do this! :-) And that's it! :-) Stephan. -
Basically you will want a way to query the status of your application, you could use a timer if needed, however when the status changes to whatever you specify, simply change the icon of your application. You could store the icons in a resource file, are you asking how you extract it? - Nick Parker
My Blog | My ArticlesI decided to change the
Icon iok=new Icon("myokicon.ico");
statements because there I hardcoded the icon and if I install my application as an addin the file is no longer found. So I decided to replace the code above by adding the iconfile as an embeded resource. So I have to access it via the resource. But I am not sure which "namespace" is ment in there. The definition for this is: namespace.filename.filetype But well is the namespace the namespace I chose for my whole WindowsForm or is it the object I assigned the ressource to (meaning an element out of the whole WindowsForm). lets say my icon is named FACE04.ICO what name does it have to be accessed with? In the main section of my WIndowsForm (Initialize) I saw something like ressource.GetObject("$this.Icon") well I guess my "filename" has to be very similar but no matter which I tried it always failed an the standardicon was used. Does the filename have to be casesensitive? Maybe one of you could tell me please, what the "filename" has to look like. I do want to create it as a global meaning I created a global icon for "OK" and one for "fail" but did not assign anything. Well to initialize it I will have to assign the icon, but what does it have to look like? I also tried the solution in the MSDN but again no icon found. The easiest way would have been to add the line in the Initialize section but you shouldn't put it there because changing the Form means this being rewritten as a whole and loosing every line which wasn't autogenerated. So I have to put it somewhere into the main. The icons should be assigned to the Window and to the notification object. Well this shouldn't be the problem, because it worked when being hardcoded. Thanks for any suggestion! Stephan.