11.3. 获得当前屏幕的角落的坐标位置:getCornerLocation
// get current right bottom corner position(X, Y), support 4 mode: taskbar bottom/right/up/left
public System.Drawing.Point getCornerLocation(Size windowSize)
{
int xPos = 0, yPos = 0;
if ((Screen.PrimaryScreen.Bounds.Width == Screen.PrimaryScreen.WorkingArea.Width) &&
(Screen.PrimaryScreen.WorkingArea.Y == 0))
{
//taskbar bottom
xPos = Screen.PrimaryScreen.WorkingArea.Width - windowSize.Width;
yPos = Screen.PrimaryScreen.WorkingArea.Height - windowSize.Height;
}
else if ((Screen.PrimaryScreen.Bounds.Height == Screen.PrimaryScreen.WorkingArea.Height) &&
(Screen.PrimaryScreen.WorkingArea.X == 0))
{
//taskbar right
xPos = Screen.PrimaryScreen.WorkingArea.Width - windowSize.Width;
yPos = Screen.PrimaryScreen.WorkingArea.Height - windowSize.Height;
}
else if ((Screen.PrimaryScreen.Bounds.Width == Screen.PrimaryScreen.WorkingArea.Width) &&
(Screen.PrimaryScreen.WorkingArea.Y > 0))
{
//taskbar up
xPos = Screen.PrimaryScreen.WorkingArea.Width - windowSize.Width;
yPos = Screen.PrimaryScreen.WorkingArea.Y;
}
else if ((Screen.PrimaryScreen.Bounds.Height == Screen.PrimaryScreen.WorkingArea.Height) &&
(Screen.PrimaryScreen.WorkingArea.X > 0))
{
//taskbar left
xPos = Screen.PrimaryScreen.WorkingArea.X;
yPos = Screen.PrimaryScreen.WorkingArea.Height - windowSize.Height;
}
return new System.Drawing.Point(xPos, yPos);
}
例 11.3. getCornerLocation 的使用范例
this.Location = crl.getCornerLocation(this.Size);