Form icon won't show in WinForms - c#

I am taking an introductory course in C# programming, and one of the objectives in my upcoming assignment is to include an icon, stored as a resource, in the WinForms application's main form (top left). All the properties of the Form are the default ones.
I have not been able to figure out why it won't work. I can create an icon resource, and it is accessible from code. The icon is named T32.ico.
this.Icon = Properties.Resources.T32;
It all compiles OK, but the actual icon showing is still the default one. I have tried 16x16 bmp and 32x32 bmp, both 8 bit and 32 bit versions.
If it matters, I'm running Windows 10 and using Visual Studio Community 2019, 16.8.2, and the application I'm writing is using .NET Framework 4.8.
Any guidance is very much appreciated.

After many hours of exploring all possible aspects, I think I found the root cause.
When creating an icon resource from within Visual Studio, there are automatically a set of different icon formats created, all within one single .ico file. The 32 bit icons are not possible to edit using the Visual Studio Image Editor, while the 8 bit icons are. For some reason, the application seems to default to one of the 32 bit icons.
By removing all but the 8 bit versions, I was able to make it work.

Related

DateTimePicker garbled after Windows 10 Creators Update

Application built with VS 2015, C#, Winforms, using the DateTimePicker Windows control, text is garbled after updating machines to the Windows Creators Update.
Has anyone else come across this or is there any suggested work around ?
Enable Visual Styles in the WinForms application, before the Form containing the DateTimePicker is shown.
Application.EnableVisualStyles();
//Form1 contains the DateTimePicker component
Application.Run(new Form1());
The June cumulative update for Windows 10 (KB 4022725) includes an updated COMCTL32.DLL that contains a fix for this issue. The file version should be 5.82.15063.413 after the update is installed.
https://social.msdn.microsoft.com/Forums/en-US/4cf03067-46c4-4962-af8c-f4b1483e88ba/date-time-picker-garbled-after-windows-10-creators-update?forum=windowsgeneraldevelopmentissues
Do you have a High-DPI display? Even if you don't, there's a good chance the updated dpi scaling is at fault here. If so, you might be able to "fix" this simply by setting a value in dpiAware and dpiAwareness values of the manifest file for your project as described here:
High-DPI Scaling Improvements for Desktop Applications in the Windows 10 Creators Update
I haven't had to do this myself yet, so right now I can only point you where to look, and not to what the exact right values should be for your situation.
Even if this isn't your issue, you may want to spend a few minutes checking that your app handles well in High-DPI situation. It's also a decent excuse to get your company to buy you a nice new monitor :)
Enabling XP Visual Styles fixed it for me.
So Windows 10 1703 has introduced some new challenges, among them this weird refusal to display a date in the DateTimePicker control, unless you tick the "Enable XP visual style" box for the application (or do it programmatically). This tweak does fix the date-rendition issue, but now other controls, such as dropdown boxes, dropdown lists text boxes and buttons become flat and dreary. Not good. What we do need is a real fix which makes the "XP visual style" unnecessary, or is Windows Forms programming on the way out and so not interesting to support?
I have also come across this today. My datetimepicker was rendered very randomly, but never acceptible. I have this as a sort-of workaround:
My environment is VS2015, .net 3.5 and winforms
My setup is Surface Pro 3 with the new docker and 2 external monitors res 2560x1440 and scaling 100%.
Added app.manifest to my project as I did not have it before.
Added the dpiAware to app.manifest to be System like this:
<application xmlns="urn:schemas-microsoft-com:asm.v3">
<windowsSettings>
<dpiAware xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">true/System</dpiAware>
</windowsSettings>
</application>
I also set the AutoScaleMode to None on my form (but got approx the same result with Inherited).
The dpiAware seemed to help (but not 100% stable). This does work when running a compiled application, but does NOT work when debugging from Visual Studio. Then I only get a period (.) that is my date separation sign.
sample of datetimepicker after updating to creators update
after applying workaround when running compiled exe
this can help a bit if unable to update application to .net 4.7
So, we wound up deleting the manifest file and the control now renders correctly.
What's odd is just the fact of including a new manifest file with only an assemblyIdentity tag with version and name causes this windows control to freak out.
I realize that for others, deleting the manifest may not be an option, but, this has fixed our issue.
We are receiving this exact same issue. VB.NET VS 2012 .NET 4.5. THe datetimepicker is messed up. I have also posted this on
https://connect.microsoft.com/VisualStudio/feedback/details/3129203/date-in-datetime-of-mfc-application-is-getting-cropped-in-win10-redstone2-build-15055
I tried most of the suggestions here and in other places including manifest changes, .NET 4.7, etc. However, one additional change that was required in my setup was to increase the CalendarFont size on the control itself.
The default on my system was 7.875. Changing it to 10pt corrected the display issue (changing it to a slightly lower value improved the display but did not correct it).
Disclaimer: This has not been tested in-depth and may break other scenarios. This information is intended to assist in finding a final solution.
Like other have suggested, had this line to your main form and it worked for me:
Application.EnableVisualStyles()
You can also uncomment the lines at the bottom in the app.manifest. It depends of the project.
A fix for this issue is scheduled to be included in the June cumulative update for Windows 10.
This is a bug in the Date Time Picker control implemented in COMCTL32.DLL version 5. There should be a fix for this issue in the near future.
The Date Time Picker control implemented in COMCTL32.DLL version 6 does not appear to be affected by this issue.

I can't get Visual Studio 2015 to change the program icon for new build's

I'm having this weird issue with Visual Studio 2015, and I'm not sure if it's my fault or if it's a glitch. I originally built this program using an icon that was dominantly black. I've since noticed that the black is way too hard to see on the Windows task bar, and even on the desktop. I updated the logo to be dominantly white with a black border to make it pop. However, when I update the .ico file in the project properties (not form properties), and rebuild the executable, it still uses the old black logo.
Here's where it gets funny. I deleted any instance of this old logo that I had (even in the project resources folder), and it still does it. It's obviously caching this file somewhere, but I don't know where, and this is really starting to bug me. If someone could help me with this or has any idea's, I'd really appreciate it!
Thanks :)
Try to rebuild the Windows IconCache.
go to C:\Users\Username\AppData\Local folder and delete the hidden
IconCache.db file. Reboot.
Source: The Windows Club
What version of Windows do you use?
You could also try deleting the iconcache files in "%localappdata%\Microsoft\Windows\Explorer\"
Source: Ten Forums

Visual Studio will not show my .ico for project icon

I've tried and scouted around for a fix but I'm surprised by the lack of info out there. This process should be so simple and easy to implement, just changing the solution's icon to an acceptable-format icon.
However, I have tried to create my own icon and VS 2015 accepts that it is the correct size/format (I don't get error that states "Argument 'picture' must be a picture that can be used as an icon." but the icon in the top left corner of my winforms stays that awful default picture icon (not the 3 red/blue/yellow computer screen mind you, but the stupid broken page/form icon?), and on my task bar it stays the same, even though I've gone through project-->properties-->application--> and included my proper .ico with the correct location. I've also changed the Icon in the winforms property tab to be the same .ico file to no avail.
I've also tried to clean/rebuild solution, restart/reinstall VS 2015 comm and nothing.
Does anyone know what's going on with this? I've put this part of my project off as long as I could as it is just a cosmetic attribute really, but it's driving me nuts something so simple is too complicated or broken. I couldn't find specific information about the dimensions needed for .ico icon in my solution, but I know it's 32x32 pixels, and I've created all the variations of a 32x32 .ico in the visual studio paint editor. Visual Studio does not display a single one of them, just the broken blank page icon instead.
Just want stupid thing to display the right icon >.>
Thanks in advance.

Visual C# icon issue

I have recently finished a Visual c# project. During the process I tried multiple icons for the form and for the icon you see on your desktop. I found one that I was gonna use for both, but for some reason the icon that you see on your desktop is the old one that I used previously even though I changed it in Properties -> Application -> Icon and Manifest
Windows File Explorer uses an icon cache. You may need to clear this cache to get it to refresh.

Why does the desktop icon differ from the explorer icon?

For some reason, a very old version of my icon keeps showing up when my application is dropped on the desktop. In the windows explorer (in all zooming levels) the icons is correctly the assembly icon. I specified the correct item in both XAML Window.Icon and in the project settings.
I have deleted the old version of my icon from all folders I can think of, but it still shows up. Also while drag and dropping, the wrong icon is shown. (in the slightly transparent preview window)
I tried cleaning and rebuilding, I tried deleting the obj folder manually...
The original, wrong icon was 16x16. I have built the new version as 32x32, because on the desktop 16x16 is too small.
According to the msdn docs (http://msdn.microsoft.com/en-us/library/system.windows.window.icon.aspx), each .ico file is supposed to incorporate all smaller sizes anyway.
I also checked that I changed the icon for both debug and release configuration.
Thanks for any ideas! :)
Could this be a problem with the IconCache? Try deleting %localappdata%\IconCache.db and restarting Explorer.exe.
Check the Visual Studio properties window for the EXE's project -- you can specify the icon that's written into the EXE at compile time. This is separate from the icon that's assigned to the XAML window at run time.

Categories