任务栏位置

如何检测任务栏的位置? 我需要知道在右上角显示我的通知。 谢谢

编辑:谢谢Hans Passant。 我用它来获取位置。 我希望没问题。

GetTaskbarLocation(TaskbarPosition.GetTaskbarPosition()); private void GetTaskbarLocation(Rectangle rc) { if (rc.X == rc.Y) { if (rc.Right  rc.Bottom) taskbarLocation = TaskbarLocation.Top; } if (rc.X > rc.Y) taskbarLocation = TaskbarLocation.Right; if (rc.X < rc.Y) taskbarLocation = TaskbarLocation.Bottom; } 

  public static Rectangle GetTaskbarPosition() { var data = new APPBARDATA(); data.cbSize = System.Runtime.InteropServices.Marshal.SizeOf(data); IntPtr retval = SHAppBarMessage(ABM_GETTASKBARPOS, ref data); if (retval == IntPtr.Zero) throw new Win32Exception("Please re-install Windows"); return new Rectangle(data.rc.left, data.rc.top, data.rc.right - data.rc.left, data.rc.bottom - data.rc.top); } // P/Invoke goo: private const int ABM_GETTASKBARPOS = 5; [System.Runtime.InteropServices.DllImport("shell32.dll")] private static extern IntPtr SHAppBarMessage(int msg, ref APPBARDATA data); private struct APPBARDATA { public int cbSize; public IntPtr hWnd; public int uCallbackMessage; public int uEdge; public RECT rc; public IntPtr lParam; } private struct RECT { public int left, top, right, bottom; } 
 SHAppBarMessage(ABM_GETTASKBARPOS) 

有关更多信息,请参阅SHAppBarMessage函数和ABM_GETTASKBARPOS消息, SHAppBarMessage的pinvoke页面有一个不易翻译的VB.Net示例。

如果传入ABM_GETTASKBARPOS消息, SHAppBarMessage函数将返回有关任务栏的信息。 它有一个out参数,它是一个指向APPBARDATA的指针,它包含任务栏的屏幕协调 。 您可以使用它来计算屏幕上的位置。

最好使用可用的API: NotifyIcon.ShowBalloonTip

 void Form1_DoubleClick(object sender, EventArgs e) { notifyIcon1.Visible = true; notifyIcon1.ShowBalloonTip(20000, "Information", "This is the text", ToolTipIcon.Info ); }