Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Form.Size when Minimized

2 views
Skip to first unread message

vooose

unread,
Dec 14, 2005, 7:37:35 PM12/14/05
to
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

--
Wal
http://www.vooose.com

*** Sent via Developersdex http://www.developersdex.com ***

Matt

unread,
Dec 15, 2005, 4:11:55 PM12/15/05
to

vooose wrote:
> 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

vooose

unread,
Dec 15, 2005, 4:43:48 PM12/15/05
to
Thanks Matt...while I was waiting for some feedback I did *exactly*
that. Great minds think alike ;)

Bruce Wood

unread,
Dec 15, 2005, 5:12:29 PM12/15/05
to
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" ...
}

vooose

unread,
Dec 16, 2005, 12:52:36 AM12/16/05
to
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

Bruce Wood

unread,
Dec 16, 2005, 12:55:40 AM12/16/05
to
0 new messages