Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Embedded icons in .exe
Message
Information générale
Forum:
ASP.NET
Catégorie:
Autre
Versions des environnements
Environment:
C# 2.0
OS:
Windows XP SP2
Network:
Windows 2000 Server
Database:
MS SQL Server
Divers
Thread ID:
01502999
Message ID:
01503464
Vues:
40
>>>>>>>>>>>>>Hi All, I've added several icons as embedded resources into my exe using the resource editor, however if I right click a shortcut to my.exe and select change icon / browse to my.exe - only the icon I set in the icon and manifest tab of the projects' properties tab is shown ? any ideas ?
>>>>>>>>>>>>
>>>>>>>>>>>>http://www.codeproject.com/KB/dotnet/embedmultipleiconsdotnet.aspx
>>>>>>>>>>>
>>>>>>>>>>>Thanks Viv, I actually read that article ( obviously not properly ! ) and couldn't get it to work - I was looking in the wrong place for Properties ! thanks again it works perfectly
>>>>>>>>>>
>>>>>>>>>>Sorry. Just noticed that the link was based on VS2005 but sounds like you found the right place to add the resource file to the app...
>>>>>>>>>
>>>>>>>>>Hi Viv, having successfuly created Resource.res - do you know how to extract an icon / cursor from one ? I've googled away but can't find much of use
>>>>>>>>
>>>>>>>>In VS just open the .res file (using File/Open)
>>>>>>>>Locate the icon that you want to extract.
>>>>>>>>Right Click , choose Export.....
>>>>>>>
>>>>>>>Hi Viv, sorry I didn't word my question very well - what I meant to ask was - now that I've embedded some icons / cursors / images etc... - how can I access them at runtime - I basically want to give certain groups of users different icons / background images etc... at runtime
>>>>>>
>>>>>>I don't think there's a simple way of retrieving from the Win32 resource file but if you add the icons to the embedded resources you could just use:
this.Icon = (Icon)WindowsFormsApplication1.Properties.Resources.ResourceManager.GetObject("RESOURCENAME");
(adjust namespace to suit)
>>>>>
>>>>>That's ok for icons but I don't think you can add cursors as embedded resources - here's what I have so far ( it ain't pretty but it works )
>>>>>
>>>>>
>>>>>[DllImport("user32.dll")]
>>>>>public static extern IntPtr LoadCursor(IntPtr hInstance, int lpCursorName);
>>>>>
>>>>>this.Cursor = new Cursor(LoadCursor(Marshal.GetHINSTANCE(Assembly.GetExecutingAssembly().GetModules()[0]),119));
>>>>>
>>>>>
>>>>>
>>>>>where 119 is my resource id ( just being silly putting it all in one statement )
>>>>
>>>>Looks good (and is probably your best bet) but, for the record, you can use the embedded resource option. In the designer just choose Add Resource/Add Existing File... and select the Cursor file. You can then retrieve it as a byte[] so:
byte[] b = (byte[]) WindowsFormsApplication1.Properties.Resources.ResourceManager.GetObject("MyCursor");
>>>>Cursor c = new Cursor(new MemoryStream(b));
>>>
>>>Thanks again, I can't find a way of accessing MyNameSpace.Properties.Resources.ResourceManager.GetObject("MyCursor"); is it a VS2010 thing ? I only get as far as MyNameSpace.Properties.Resources and intellisense stops ?
>>
>>I think it's the same in both. But I set the Access Modifier to 'Public' in the designer - I think the default is Internal. If you make it public Intellisense should work. Actually, since MyCursor is then public you could just use:
Cursor c = new Cursor(new MemoryStream(WindowsFormsApplication1.Properties.Resources.MyCursor));
Of course you could change the return type of MyCursor in the Resources.Designer.cs and create the cursor there leaving just:
this.Cursor= WindowsFormsApplication1.Properties.Resources.MyCursor;
>
>Good stuff thanks again - good thread

The last suggestion is not particularly useful since the .cs file will be regenerated if you make changes to resources from the Project properties tab.....
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform