How can I bring a minimized modeless WinForm to it

2019-06-24 01:44发布

问题:

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:

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();
}