Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Multiple Application Icons? 1

Status
Not open for further replies.

RexHeadlong

Programmer
Apr 10, 2002
35
US
This question might be more of a VS .NET question than straight C#, but here goes.

I'm trying to set up a method by which my application can be compiled using one of two different application icons. So, when I build it one way, I get my .exe with one icon associated with it. But, if I build it another way, I get the same .exe with a different icon associated with it.

Unfortunately, the Application Icon isn't a property that can be set differently for different build configurations.

I tried duplicating the .csproj file for my project. This way, I have two 'projects' in the same folder. The only differences are the GUIDs and the Application Icon. This method works, but the drawback is that any changes made to one .csproj file must be manually duplicated in the other .csproj file. In a multi-developer environment it will be tough to enforce this rule.

Does anybody know a programmatic way to determine which application icon to use?

Thanks for any help.
 
Here is the one solution:
In the Project Properties -> Common Properties->Build Events ->Pre bilt Event Command line , click on ... and type in , for example:
seticon.bat myappicon.icon
Now, if you Build the project and you take a look in \Debug or \Release or another configuration you should see the autogenareted PreBuildEvent.bat which contains:
Code:
@echo off
seticon.bat myappicon.ico
if errorlevel 1 goto CSharpReportError
goto CSharpEnd
:CSharpReportError
echo Project error: A tool returned an error code from the build event
exit 1
:CSharpEnd

but the Build failed.
Next is to provide in \debug the seticon.bat to copy the myappicon.ico that you want to be used by build action:
So add something like that:
Code:
copy C:\\icons\\%1  C:\\My projects\Project1\Debug\appicon.ico
You should have the myappicon.ico to copy into the destination folder

Repeat the same in the \Release folder e.g. create seticon.bat there with
Code:
copy C:\\icons\\%1  C:\\My projects\Project1\Release\appicon.ico
Next, in the code, you can load the "appicon.ico" as the application icon in many ways. One is like here:
mainForm.Icon = new Icon("appicon.ico"); // will load one that was copied into /Debug or /Release folder depending on which you passed as parameter in the Project Properties before build.
-obislavu-

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top