Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to change "this.ShowInTaskBar" for a "form.ShowDialog()" while keeping it open?

Tags:

c#

.net

winforms

if you run this snippet of code(put it in form1) in a fresh new winform app with 2 forms

    private void Form1_Load(object sender, EventArgs e)
    {
        Form2 newForm = new Form2();
        Button b = new Button();
        newForm.Controls.Add(b);
        b.Click += new EventHandler(click);
        this.Show();
        newForm.ShowDialog();

    }

    private void click(object sender, EventArgs e)
    {
        ((Form)((Control)sender).Parent).ShowInTaskbar = false;
    }

and you click on the button on the new form(should be form2), form2 will close.

How to keep it open?

like image 677
Fredou Avatar asked Mar 06 '10 00:03

Fredou


1 Answers

It is not possible. I actually filed a bug report about it at Microsoft's feedback site but they flipped me the bird on it.

Admittedly, it is a tricky problem to solve, changing the property requires Windows Forms to recreate the window from scratch because it is controlled by a style flag. The kind you can only specify in a CreateWindowEx() call with the dwExStyle argument. Recreating a window makes it difficult to keep it modal, as required by the ShowDialog() method call.

Windows Forms works around a lot of User32 limitations. But not that one.

like image 148
Hans Passant Avatar answered Sep 23 '22 23:09

Hans Passant