I have a WinForms application. I've set up the executable's icon (with at least 16x16 and 32x32 formats) in project settings and it is successfully shown in Explorer and elsewhere for .exe file.
How can I set this icon as form's icon (Form.Icon property or something)? It may be used in form's header at left and it will be used to show form in taskbar.
As I know, System.Drawing.Icon can't be created with multiple icon formats, but.. when user has his taskbar with 'small icons' enabled, the icon for taskbar should be 16x16. When this option is disabled, it should be 32x32. If icon has wrong size, the windows will scale it and it will look terrible.
Icon.ExtractAssociatedIcon gives me only one format (32x32). P/Invoking ExtractIconEx gives me both formats (16x16 and 32x32), but I unable to combine it in one System.Drawing.Icon instance to set to Form.Icon.
Of course, I can set the icon with form's properties from .ico file, but it will give me the resource duplication: one icon is stored in PE as executable's icon and another is stored as .NET resource.
Again, the question is: what settings I should use to make the exe's icon to be form's icon and work as it should with any taskbar settings?
It seems like the default icon handling routines in Windows and .Net don't extract multisize icons from modules well. The Icon class has tricky usage where it pulls in all the data from an icon file and then only uses one size, and you can create a new Icon object from that original Icon for a different size and it will share the data and extract the nearest size. Unfortunately methods to easily work with multi size icons aren't really included.
Here is code that will let you do what you want from Code Project, written for exactly your purpose: assigning the multisize icon from the EXE file to your forms.
Assigning an applications icon to all the forms in the application
Once you have the library added to your project, you can just assign the singleton property HostIcon to your form's icon property:
this.icon = Cliver.IconRoutines.HostIcon;
Related
I'm developing a WPF that needs to make desktop icons and folder icons bigger while the WPF is active
and returns them to their previous state when closing the WPF
basically I want to be able to control the following options programmatically:
Folders icons :
desktop icons:
also how to change folder option to single click mode :
Folder icon settings are often per-folder and you will have a hard time forcing your preferences on them. You can probably find some descriptions of the registry locations and format if you search the internet for "shellbags" but this puts you in undocumented territory.
The desktop icon mode can probably be changed by undocumented/hacky means but you should just let the user do it.
You might be able to change the double-click mode by playing with fDoubleClickInWebView and SHGetSetSettings.
When I run my wpf application in debug mode, the icon on the taskbar looks fine (left image), but after I published and open the application, the icon looks pixelated (right image).
I've referred to this link and I set the icon image to 256x256, but still looks pixelated.
Please help.
try using an ico editor to save the icon with all the correct resolutions (the OS will display the correct one). I use icofx, but there are many options if you google it - they should all correct your image proportions. Most should have an equivalent option to the 'save windows icon' (in icofx) where you select all the resolutions you want to add to the file.
Just another thought - is you icon a resource file? If so you may need to remove it then add it again and make sure the resource is set to publish correctly (so you are not using an old version).
I will like to load the timer icon in main form icon, but can't find where it is stored.
So my question is: In which dll are icons of components stored (where is the timer icon stored)?
The icons you are referring to are embedded into the .NET Framework assemblies as resources. You can get various images and icons from here.
I made a icon overlay to my file, *.myfile, but the overlay size is wrong. When the icon shows in size 16x16, the overlay covers the icon.
How can I change the overlay size? (IShellIconOverlayIdentifier)
You can't change the overlay size. Instead use a multi-resolution icon file where all necessary sizes are available.
For a good example take a look into the source of TortoiseSVN. Their will be only one icon file used, but if you open it with an appropiate paint tool, you'll see that this file contains different sizes.
Update
If you take a look right at the first method, you'll get the following comment:
"The Shell calls IShellIconOverlayIdentifier::GetOverlayInfo to request the
location of the handler's icon overlay. The icon overlay handler returns
the name of the file containing the overlay image, and its index within
that file. The Shell then adds the icon overlay to the system image list."
You can see in line 129 that it tries to find out the path of the needed file from the registry. By browsing the code you can find the icons in subversion here. In line 165 you can see that it takes the filename from the registry and writes it back to its out parameters and maybe the magic flag to let windows decide which size should be taken from the file is *pdwFlags = ISIOI_ICONFILE;.
Currently my WPF apps have the "unknown document" type of icons. I don't want to design icons for each but something like the default icon for Winform apps would be very good.
You have to set the windows icon for each window (or at least for your main window). This is the icon that is shown in the windows title and in task-manager. Be aware that the window icon should not be an .ico-file having huge resolution icons, else it will fail on windows XP. You can also use a png-file.
<Window
...
Icon="/Assembly;component/imagePath/yourImage.png"
Title="Window Title"...>
The other icon is the icon in the projects properties page. This icon is used as the file icon. You must use an .ico-file. However for this, you can use also highres icon-files (for showing huge icons in Vista+ -explorer).