Form.Size when Minimized

V

vooose

Consider a Form with dimension Size=(300,300) that is then minimized.
Subsequent calls to Size return (160,24).

The Form is then restored and Size returns (300,300)

Is there any property or method that returns the size of the form when
restored? (so you can obtain the "real" size of the Form when it is
minimized)

Regards
 
M

Matt

vooose said:
Consider a Form with dimension Size=(300,300) that is then minimized.
Subsequent calls to Size return (160,24).

The Form is then restored and Size returns (300,300)

Is there any property or method that returns the size of the form when
restored? (so you can obtain the "real" size of the Form when it is
minimized)

There's a private Form member called restoredWindowBounds, but that
obviously won't help you.

The easy way to do this is to trap the Resize event, note whether or
not
the form is minimized and keep track of it.

Matt
 
V

vooose

Thanks Matt...while I was waiting for some feedback I did *exactly*
that. Great minds think alike ;)
 
B

Bruce Wood

There is a way to get this information by calling base Win32 methods.

/// <summary>
/// The WINDOWPLACEMENT structure for the Win32 interface.
/// See Microsoft documentation for details.
/// </summary>
private struct Win32WindowPlacement
{
public UInt32 length;
public UInt32 flags;
public UInt32 showCmd;
public Win32Point minPosition;
public Win32Point maxPosition;
public Win32Rect normalPosition;

public Win32WindowPlacement(UInt32 length, UInt32 flags,
UInt32 showCmd, Win32Point minPosition,
Win32Point maxPosition, Win32Rect normalPosition)
{
this.length = length;
this.flags = flags;
this.showCmd = showCmd;
this.minPosition = minPosition;
this.maxPosition = maxPosition;
this.normalPosition = normalPosition;
}

public Size WindowSize
{
get
{
return new Size(this.normalPosition.Width,
this.normalPosition.Height);
}
}
}

/// <summary>
/// The POINT structure for the Win32 interface.
/// See Microsoft documentation for details.
/// </summary>
private struct Win32Point
{
public Int32 x;
public Int32 y;
public Win32Point(Int32 x, Int32 y)
{
this.x = x;
this.y = y;
}
}

/// <summary>
/// The RECT structure for the Win32 interface.
/// See Microsoft documentation for details.
/// </summary>
private struct Win32Rect
{
public Int32 left;
public Int32 top;
public Int32 right;
public Int32 bottom;
public Win32Rect(Int32 top, Int32 left, Int32 bottom, Int32 right)
{
this.top = top;
this.left = left;
this.bottom = bottom;
this.right = right;
}

public Int32 Width
{
get { return this.right - this.left; }
}

public Int32 Height
{
get { return this.bottom - this.top; }
}
}


[DllImport("user32.dll", SetLastError=true)]
static extern bool GetWindowPlacement(IntPtr hDc, out
Win32WindowPlacement placementInfo);

and then...

IntPtr windowHandle = theForm.Handle;
Win32WindowPlacement placement;
if (GetWindowPlacement(windowHandle, out placement))
{
... get form's true size from "placement.WindowSize" ...
}
 
V

vooose

Thanks Bruce - I have used the struct and it gives me the answer i want!
May I ask where you got the struct code from?

Regards
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top