Hi TS,
First, just as Alex pointed out, we should note the existence of form
border. Then I will explain the details for you.
1. Form.Width and Heigth property will return the whole width and height of
the form, including non-client area such as border size. In my side, when
the form is maximized Form.Width and Height returns 1032, 744. But my video
setting is 1024X768. Why?
This is because when form is maximized, the left and right border of the
window will get out of the screen display area, while Form.Width added in
the 2 border width. So its value is larger than display area width of 1024.
For sizable normal window, we may use SystemInformation.FrameBorderSize
property to get the width of the border. It is 4 on my side. So you will
see Form.Top=Form.Left=-4(They all go out of the display area)
Because Form.Width- 2*SystemInformation.FrameBorderSize=1024, the
Form.Width value is correct.
2. For Form.Heigth property, the situation is a little complex, because the
taskbar's height is taking into acount, and when the form is maximized, the
form's top border will go out of the display area. Also, form's bottom
border will be overlayed by the taskbar.(Task bar also has borders, we may
use SystemInformation.Border3DSize to get its value, it is 2 in my side)
We may use the code snippet below to get the taskbar's height:
[DllImport("user32.dll")]
static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
[DllImport("user32.dll")]
static extern bool GetWindowRect(IntPtr hWnd, out RECT lpRect);
public struct RECT
{
public int left;
public int top;
public int right;
public int bottom;
}
private void button1_Click(object sender, System.EventArgs e)
{
IntPtr hwnd=FindWindow("Shell_TrayWnd", string.Empty);
RECT rect=new RECT();
GetWindowRect(hwnd, out rect);
Console.WriteLine("rect.bottom:"+rect.bottom.ToString());
Console.WriteLine("rect.top:"+rect.top.ToString());
Console.WriteLine("Form.top:"+this.Top.ToString ());
Console.WriteLine("Form.bottom:"+this.Bottom.ToString ());
Console.WriteLine("rect.left:"+rect.left.ToString ());
}
The output in my side is:
rect.bottom:770
rect.top:736
Form.top:-4
Form.bottom:740
rect.left:-2
As you can see, Form.bottom-Form.top=744=Form.Height.
While rect.top is 4 pixel less than Form.bottom, which means the taskbar is
hidding form's bottom border.
"rect.left:-2" means the taskbar's border is 2 pixel the same as
SystemInformation.Border3DSize.
Then 768=rect.bottom-2, so the taskbar's bottom border is also go out of
the display area of video.
Hope this details explain helps you. If you you still have anything
unclear, please feel free to tell me, I will work with you. Thanks
Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! -
www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.