.NET Core Version: 3.0, 3.1.2
Have you experienced this same bug with .NET Framework?: No
Problem description:
In WinForms core app run this.ShowIcon = false; Icon is hiding, but default app. icon appear:

Expected behavior:
Icon is hiding:

Windows 7 x64.
Minimal repro:
WinFormsCoreTest1.zip
This is not MDI related problem, it's a problem of every form. 100% regression from .net :(
I've updated 1 post,
I think this is caused by swapping the condition under which UpdateStyle is called:
UpdateStyle when ShowIcon switches to falseUpdateStyle when ShowIcon switches to true@weltkante
I think this is caused by swapping the condition under which UpdateStyle is called:
DesktopFramework calls UpdateStyle when ShowIcon switches to false
.NET Core calls UpdateStyle when ShowIcon switches to true
Yea, I saw it and tried this:
ShowIcon = false;
UpdateStyles();
with no luck. May be it's critical that UpdateStyles(); must be called before UpdateWindowIcon(true); ? ...
Yeah, calling UpdateWindowIcon with incorrect styles messes something up that doesn't repair itself. I tried calling UpdateWindowIcon(true) via reflection after doing your UpdateStyles but that doesn't help, yet this works (replicated ShowIcon behavior from Desktop Framework via reflection):
var value = !ShowIcon;
var vectorField = typeof(Form).GetField("formStateEx", BindingFlags.Instance | BindingFlags.NonPublic);
var vector = (BitVector32)vectorField.GetValue(this);
var section = (BitVector32.Section)typeof(Form).GetField("FormStateExShowIcon", BindingFlags.Static | BindingFlags.NonPublic).GetValue(this);
vector[section] = value ? 1 : 0;
vectorField.SetValue(this, vector); // struct field needs explicit update
if (!value) UpdateStyles();
typeof(Form).GetMethod("UpdateWindowIcon", BindingFlags.Instance | BindingFlags.NonPublic).Invoke(this, new object[] { true });
I can certainly understand this is an annoying bug.
Is this a blocker? If so, what's the impact? We need to have a good justification for servicing to accept a fix.
@RussKie Maybe this is a known issue in core designer.
There is no icon shown in runtime when setting the Form鈥檚 ShownIcon property to false in property browser(press F4 when focus on the form) or setting it in InitializeComponent() part.



I can certainly understand this is an annoying bug.
Is this a blocker? If so, what's the impact? We need to have a good justification for servicing to accept a fix.
In our app we have _worker_ forms, each of them have 3 states differ (to the user) by form icon:
This is a key point and users are used to it. So, yes this is a blocker :(
@Vino-Wang Yes, I think this is related to this and 2 posts down.
- Working - no icon.
This is a key point and users are used to it. So, yes this is a blocker :(
As a workaround could you not set an empty transparent icon?
Another workaround is to perform an interop call to hide the icon _before_ hiding the icon:
if (myform.ShowIcon)
{
int extendedStyle = (int)User32.GetWindowLong(myform.Handle, User32.GWL.EXSTYLE);
User32.SetWindowLong(myform.Handle, User32.GWL.EXSTYLE, (IntPtr)(extendedStyle | (int)User32.WS_EX.DLGMODALFRAME));
}
myform.ShowIcon = false;
@RussKie Yes, thank you. Of course we can do such a workarounds, but if this was the only problem. As I mentioned in this post, we are stopped our migration to core process, so no workarounds (for us) currently needed :(
This is a very simple fix per @Tanya-Solyanik , I'd be willing to take it to Servicing shiproom if @kirsan31 would be able to continue the migration exercise, even though it's possible to work around the issue.
Let's mark this a known issue for 3.1 including the workaround.
Verified the issue with latest .NET Core SDK 5.0, the issue has been fixed that hide the icon of the form successfully in running.
