winform 通过调用系统底层方法,获取任务栏位置信息,来计算自己窗体的显示处理.
1.注册底层方法
[DllImport("user32.dll")]
public static extern int FindWindow(string lpClassName, string lpWindowName);
[DllImport("user32.dll")]
public static extern int GetWindowRect(int hwnd, ref Rectangle lpRect);
2.获取位置信息
if (GetWindowRect(FindWindow("Shell_TrayWnd", null), ref myrect) == 0) return;
zleft.Text = Convert.ToString(myrect.Left);
ztop.Text = Convert.ToString(myrect.Top);
zright.Text = Convert.ToString(myrect.Right);
zbottom.Text = Convert.ToString(myrect.Bottom);
zwidth.Text = Convert.ToString(myrect.Width);
zheight.Text = Convert.ToString(myrect.Height - myrect.Top);