当前位置: 动力学知识库 > 问答 > 编程问答 >

windows - C#, FormBorderStyle:None Restore Issue

问题描述:

I have an app that uses Forms with FormBorderStyle set to "None."

The issue with this is that if a user hits the "Show Desktop" button (which effectively minimizes all opened windows) and then restores one of the Forms from the taskbar, all of the borderless forms will be restored.

Note: If the form was explicitly minimized (i.e. WindowState = FormWindowState.Minimized) before the Show Desktop button is clicked, then it results in expected behavior for that particular form.

Also note that this is not the case for regular forms or even WPF windows without borders.

Form.Designer.cs:

this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;

Form.cs:

private void MinimizeButton_Click(object sender, EventArgs e)

{

// If minimized explicitly, form behaves appropriately

WindowState = FormWindowState.Minimized;

}

Any ideas on why this is the case/how to fix it?

网友答案:

I believe that this is just the default behavior since border-less form is not supposed to be minimized.

Check out this post. Hopefully it will help you change this default behavior.

From the post (add to the Form):

const int WS_MINIMIZEBOX = 0x20000;
const int CS_DBLCLKS = 0x8;
protected override CreateParams CreateParams
{
    get
    {
        CreateParams cp = base.CreateParams;
        cp.Style |= WS_MINIMIZEBOX;
        cp.ClassStyle |= CS_DBLCLKS;
        return cp;
    }
}
分享给朋友:
您可能感兴趣的文章:
随机阅读: