using System.Drawing; using System.Windows.Forms; using Vanara.Extensions.Reflection; using Vanara.PInvoke; namespace Vanara.Extensions { /// Extension methods for . public static partial class NotifyIconExtensions { /// Gets the screen coordinates of the bounding rectangle of a notification icon. /// The instance to process. /// /// A structure that, when this function returns successfully, receives the coordinates of the icon. /// public static Rectangle GetBounds(this NotifyIcon trayIcon) { // Super sketchy way of doing this, but it works var iconid = trayIcon.GetFieldValue("id"); NativeWindow win = trayIcon.GetFieldValue("window"); var nii = new Shell32.NOTIFYICONIDENTIFIER(win.Handle, iconid); Shell32.Shell_NotifyIconGetRect(nii, out RECT loc).ThrowIfFailed(); return loc; } } }