Skip to content

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

@ghost

Description

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions