when ShowinTaskBar is false, the window disappears

.net, vb.net

Solution

This is a bug in Winforms. The ShowInTaskbar property is a very non-trivial one, it can only be specified when the native window is created. Under the hood, it is a style flag that's passed to the CreateWindowEx() winapi function, the WS_EX_APPWINDOW style has to be used in the first argument to get the taskbar button to display.

Problem is, by the time the Load event fires, that call was already made. It was the CreateWindowEx() call that got the Load event to fire. So Winforms has to do something very nontrivial, it has to destroy the native window and recreate it again, now using a different value for the first argument. That usually works just fine, but sometimes things go wrong. It interacts very poorly with the ShowDialog() call in your case. Which ensures that a dialog is automatically closed when the dialog window closes or is hidden. It was closed, as a side-effect of your ShowInTaskbar assignment. But of course for the wrong reason.

You must ensure that the property is set before the Load event fires. You do so by using the constructor of the form. Fix:

Public Sub New()
    InitializeComponent()
    Me.ShowInTaskbar = False
End Sub

Or just set the property in the Properties window when you design the form.

Problem

In my application, i have the main form, and the child form. I want to set `ShowIntaskBar` to false for the child form, but the problem is that when i open it by a menu, it appears and disappears faslty, then when i open it again, it become visible. so i don't want to open it twice to see it. how to resolve this problem ? The Child form code : ``` Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Me.ShowInTaskbar = False End Sub ``` The parent (main) form code: ``` Private Sub إضافةبائعجديدToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles إضافةبائعجديدToolStripMenuItem.Click Form1.ShowDialog() End Sub ```

Original source