question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Setting ShowInTaskbar to false causes the form to close automatically (Abnormal exit).

See original GitHub issue

Setting 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:

  1. Run the appliction.
  2. Click the first button, the application will open a new Form.
  3. Click the first button in new form.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:4
  • Comments:30 (27 by maintainers)

github_iconTop GitHub Comments

2reactions
RussKiecommented, Jan 18, 2022

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.

0reactions
AraHaancommented, May 2, 2022

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found