Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WinForms: finding the size of a minimized form without going to FormWindowState.Normal

Tags:

c#

.net

winforms

Is there an easy way to determine the size of a Form it does have in WindowState=Normal, without actually changing the Form state?

Here is what I do now (C# code):

public class MyForm: Form
{
     public void MyMethod()
     {
          // ...
          FormWindowState oldState = this.WindowState;
          this.WindowState = FormWindowState.Normal;

          Point windowLocation = this.Location;
          Size windowSize = this.Size;

          this.WindowState = oldState;
          //  ...
     }
}

This is what I would like the code to look like:

public class MyForm: Form
{
     public void MyMethod()
     {
          // no state change here
          Point windowLocation = this.NormalStateLocation;
          Size windowSize = this.NormalStateSize;
     }
}

In fact there are no NormalStateLocation or NormalStateSize properties in Windows Forms.

like image 380
Doc Brown Avatar asked May 20 '10 17:05

Doc Brown


1 Answers

Since .NET 2.0, there is a property RestoreBounds that contains values you need.

like image 92
Bohumil Janda Avatar answered Nov 10 '22 02:11

Bohumil Janda