有沒有辦法在Windows 7和Windows Vista中單擊的通知圖標上方放置表格?在點擊的通知圖標上方的位置表格
回答
關於您的評論:「我怎麼知道任務欄是如何定位的?」
看看下面的文章包含暴露用於檢索托盤Rectangle Structure的方法的類:[c#] NotifyIcon - Detect MouseOut
使用這個類可以檢索Rectangle Structure的托盤,像這樣:
Rectangle trayRectangle = WinAPI.GetTrayRectangle();
這將爲您提供托盤的頂部,左側,右側和底部座標及其寬度和高度。
我已經包含下面的類:
using System;
using System.Runtime.InteropServices;
using System.Drawing;
using System.ComponentModel;
public class WinAPI
{
public struct RECT
{
public int left;
public int top;
public int right;
public int bottom;
public override string ToString()
{
return "(" + left + ", " + top + ") --> (" + right + ", " + bottom + ")";
}
}
[DllImport("user32.dll", CharSet = CharSet.Auto)]
public static extern IntPtr FindWindow(string strClassName, string strWindowName);
[DllImport("user32.dll", SetLastError = true)]
public static extern IntPtr FindWindowEx(IntPtr parentHandle, IntPtr childAfter, string className, IntPtr windowTitle);
[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
static extern bool GetWindowRect(IntPtr hWnd, out RECT lpRect);
public static IntPtr GetTrayHandle()
{
IntPtr taskBarHandle = WinAPI.FindWindow("Shell_TrayWnd", null);
if (!taskBarHandle.Equals(IntPtr.Zero))
{
return WinAPI.FindWindowEx(taskBarHandle, IntPtr.Zero, "TrayNotifyWnd", IntPtr.Zero);
}
return IntPtr.Zero;
}
public static Rectangle GetTrayRectangle()
{
WinAPI.RECT rect;
WinAPI.GetWindowRect(WinAPI.GetTrayHandle(), out rect);
return new Rectangle(new Point(rect.left, rect.top), new Size((rect.right - rect.left) + 1, (rect.bottom - rect.top) + 1));
}
}
希望這有助於。
這是一個怪誕的黑客。爲什麼你會這樣做,而不是從右鍵單擊事件讀出光標pos?爲什麼訴諸黑客,當你可以正確地做到這一點? –
@David Heffernan什麼是正確的方式來獲取任務欄的位置?我只需要知道它是在左/右/上/下。 – blejzz
@blejzz漢斯已經解釋說你找不到你的圖標。你可以做的是獲得調用你的圖標上下文菜單的事件的光標pos。從那你可以找出哪個角落。 –
這是一個更簡單的方法。
當OnClick事件被觸發時,您可以獲得鼠標的X,Y位置。 您還可以通過這些對象的某些檢查來獲取任務欄位置Screen.PrimaryScreen.Bounds
,Screen.PrimaryScreen.WorkingArea
。
private void OnTrayClick(object sender, EventArgs e)
{
_frmMain.Left = Cursor.Position.X;
_frmMain.Top = Screen.PrimaryScreen.WorkingArea.Bottom -_frmMain.Height;
_frmMain.Show();
}
- 1. 鼠標點擊圖片上的位置
- 2. 在鼠標點擊獲取ms圖表中的標記位置
- 3. 在asp.net上彈出的按鈕點擊或圖標(通知)
- 4. 位圖的通知圖標
- 5. 通過點擊通知圖標在鎖屏上方顯示Android活動
- 6. 點擊一次部署後的通知圖標設置
- 7. 重點雙擊通知圖標
- 8. 鼠標單擊圖像上的位置
- 9. 通知點擊的Android通話方法
- 10. 點擊表格視圖中的標籤?
- 11. 如何讓鼠標在imageview的點擊位置上定位?
- 12. 鼠標點擊位置上的PictureBox未檢測到在標籤
- 13. 在地圖上點擊設置標記
- 14. 更改多個谷歌地圖標記的位置上點擊
- 15. 如何在Matlab圖形軸上獲得鼠標點擊位置?
- 16. android通知,而通知圖標被點擊
- 17. 在地圖上通過點擊添加標記並按住位置
- 18. 確定點擊柵格中點擊的位置,在R
- 19. 單擊通知圖標
- 20. 谷歌通知上的點擊事件
- 21. Matplotlib:通過鼠標點擊圖表上的區域
- 22. 知道點擊圖片時的座標
- 23. 如何在頁面上的任意位置點擊鼠標X和Y位置?
- 24. 顯示列表視圖項在谷歌地圖上點擊的位置
- 25. 點擊圖標放置在地圖上的事件
- 26. 更改標記的位置點擊
- 27. 在點擊位置
- 28. 識別Android上點擊當前位置標記谷歌地圖
- 29. Android地圖v2 - 在標記點擊時獲取標記位置
- 30. 上的ImageButton的Android咖啡點擊點擊錯誤的位置
這對你有幫助嗎? http://codetechnic.blogspot.com/2009/03/set-windows-forms-start-position-to.html – Zenwalker
沒有,它將窗體放置在任務欄上方的右下角。我需要將它放在通知圖標上方。 – blejzz
可能的重複:http://stackoverflow.com/questions/272778/how-to-find-the-location-of-the-icon-in-the-system-tray –