How can I bring a minimized modeless WinForm to it

2019-06-24 01:47发布

To bring a modeless Windows Form to its previous position upon a click event, I am trying to use the code shown below, but its not working.

Please let me know if I am missing anything.

public void SetFocus()
{
    this.Focus();
    this.BringToFront();
    if (this.WindowState==FormWindowState.Minimized)
        this.Select();
}

1条回答
趁早两清
2楼-- · 2019-06-24 02:41

If the form is minimized and you want to make it visible, you'll need to restore it. You do this by setting its WindowState property to FormWindowState.Normal.

For example, change your code to this instead:

public void SetFocus()
{
    if (this.WindowState == FormWindowState.Minimized)
        this.WindowState = FormWindowState.Normal;
    this.Focus();
    this.BringToFront();
}
查看更多
登录 后发表回答