Multiple icons in C # 2.0 WinApp

I have a little problem with my winforms.net 2.0 application. I want to add several different icons to my application.

There are other requirements as well:

  • ms-assembly should be automatically rebuilt; using external GUI applications for provisioning is not allowed
  • application must contain version info.

After embedding a few icons, I want to register, say, two file associations in application documents / extension files.

[Registry]
...
Root: HKCR; Subkey: "MyFileExt\DefaultIcon"; ValueType: string; ValueName: ""; ValueData: "{app}\MyApp.exe,2"

      

where "2" is the icon.

I know I need to use some old Win32 resource file.

I also found that if using Visual Studio 2005 it is possible to add a "native resource file", but it no longer exists in 2008.

Is it possible to meet all these requirements, and if so - how?

0


source to share


6 answers


I decided to put all the icons in a separate old school win32 C ++ * .dll version. This is more convincing and I don't need to do any tricks with versioninfo / win32resources.



0


source


The solution is actually pretty simple, although I need to get me back to my first encounter with RC files ...

In a text file, you can write the following

#include <windows.h>

// The following is some Win32 candy for
// -- the Windows styles in XP, Vista & 7
//    does the UAC too.
1 RT_MANIFEST "App.manifest"
// -- the versioning info, which we find usually in 
//    AssemblyInfo.cs, but we need to add this one
//    because including Win32 resources overrides the .cs
//    file!
VS_VERSION_INFO VERSIONINFO
FILEVERSION     1,0,0,0
PRODUCTVERSION  1,0,0,0
FILEFLAGSMASK   VS_FFI_FILEFLAGSMASK
FILEFLAGS       VS_FF_DEBUG
FILEOS          VOS__WINDOWS32
FILETYPE        VFT_DLL
FILESUBTYPE     VFT2_UNKNOWN
BEGIN
    BLOCK "StringFileInfo"
    BEGIN
        BLOCK "040904E4" // en-US/cp-1252
        BEGIN
            VALUE "CompanyName",      "My Company"
            VALUE "ProductName",      "My C# App"
            VALUE "ProductVersion",   "1.0.0.0"
        END
    END
        BLOCK "VarFileInfo"
        BEGIN
            VALUE "Translation", 0x409, 1252 // en-US in ANSI (cp-1252)
        END
    END
END

// And now the icons.
// Note that the icon with the lowest ID
// Will be used as the icon in the Explorer.
101 ICON "Icon1.ico"
102 ICON "Icon2.ico"
103 ICON "Icon3.ico"

      

(Details on the VERSIONINFO structure can be found on MSDN: VERSIONINFO

structure
)

You are compiling with rc

which should be part of VS or the Windows Platform SDK. The result of compiling your file .rc

is a file .res

that can be included in your C # project's property page or added to a file .csproj

.



<Win32ResourceFile>C:\path\to\my\resource\file.res</Win32ResourceFile>

      

Compile your project and look in explorer, information and icons should be there.

The CSC compiler also provides a switch /win32res

that inserts the file .res

into your application.

Hope this helps!

+2


source


As in 2005, you can add icons to assets (via project properties). After that, navigate to the icons that you added to the project explorer. Each icon has a BuildAction property for how this resource is stored and used.

I think you are looking for the EmbeddedResource value of the BuildAction property.

+1


source


New WinForms Application -> Expand Properties in Solution Explorer -> Double click on Resource.resx -> Click Add Resource (dropdown also includes adding existing resources)

They should be available to you in the visual designer or in code using properties. Resources. [Your resource name here]

Hope it helps.

0


source


When I need multiple icons, I have nested png / bmp (or any type of image) as an image resource in the application. Go to Project -> Properties -> Resoruces in Visual Studio.

In code, you can do the following at runtime:

buttonPlay.Image = Properties.Resources.Navigation_Media_Pause;

      

or

buttonPlay.Image = Properties.Resources.Navigation_Media_Play;

      

Assuming you have called 2 image resources "Navigation_Media_Pause" and "Navigation_Media_Play".

0


source


Compile the app, then open the .exe with visual studio, then you can add all the icons you want.

There is also something you can do with win32 resource files in C #, but I cannot find that at the moment

0


source







All Articles