Setting ShowInTaskbar to false causes the form to close automatically (Abnormal exit).
See original GitHub issueSetting ShowInTaskbar to false causes the form to close automatically (Abnormal exit).
https://docs.microsoft.com/en-us/dotnet/api/system.windows.forms.form
Test Code: .NET 6.0 (Version: 6.0.1)(This problem also appears in .net framework 4.8) Win10 system (21H2).
using System;
using System.Windows.Forms;
namespace FormShowInTaskbarTest
{
internal static class Program
{
private static Form form1;
private static Form form2;
[STAThread]
static void Main()
{
ApplicationConfiguration.Initialize();
form1 = new Form()
{
Width = 800,
Height = 600,
StartPosition = FormStartPosition.CenterScreen,
};
var button1 = new Button()
{
Text = "Click here to open new Form.",
Width = 200,
Height = 100,
};
button1.Click += Button1_Click;
form1.Controls.Add(button1);
Application.Run(form1);
}
private static void Button1_Click(object sender, EventArgs e)
{
form2 = new Form()
{
Width = 600,
Height = 400,
StartPosition = FormStartPosition.CenterScreen,
};
var button2 = new Button()
{
Text = "Click here to test ShowInTaskbar.",
Width = 200,
Height = 100,
};
button2.Click += Button2_Click;
form2.Controls.Add(button2);
form2.ShowDialog(form1);
}
private static void Button2_Click(object sender, EventArgs e)
{
form2.ShowInTaskbar = false;
}
}
}
Steps to reproduce:
- Run the appliction.
- Click the first button, the application will open a new Form.
- Click the first button in new form.
Issue Analytics
- State:
- Created 2 years ago
- Reactions:4
- Comments:30 (27 by maintainers)
Top Results From Across the Web
when ShowinTaskBar is false, the window disappears
This is a bug in Winforms. The ShowInTaskbar property is a very non-trivial one, it can only be specified when the native window...
Read more >Showing form without owner and ShowInTaskBar set to ...
This leak only occurs when no owner (or a null owner) is passed to Show/ShowDialog AND ShowInTaskbar is set to false for the...
Read more >Form.ShowInTaskbar Property (System.Windows.Forms)
Gets or sets a value indicating whether the form is displayed in the Windows taskbar.
Read more >WINDOWS FORMS
the Application class decides it is time to exit. By default, this is when the main form is closed. The Application Class. To...
Read more >How can I prevent a form from being shown in the taskbar?
You need to set the form's ShowInTaskbar property to False to prevent it from being displayed in the Windows taskbar.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

I have run the provided sample on Win11 (10.0.22000 Build 22000), and confirmed the behaviour is consistent as far as .NET Framework 4.7.2 and all the way up to .NET 7 Preview1.
@Olina-Zhang would you be able to test 6421.zip on different versions of Windows 10 and see if there are any differences in behaviours? Thank you.
Wait why is System.Private.Winforms preview 4 still?
Sad it don’t add an download link that links to the azureblobstorage location of them either.