单击的通知图标上方

单击的通知图标上方

有没有办法将窗体放置在 Windows 7 和 Windows Vista 中单击的通知图标上方?

最佳答案

关于您的评论:“我怎么知道任务栏是如何定位的?”

查看以下文章,其中包含一个公开用于检索托盘的 Rectangle Structure 的方法的类:[c#] NotifyIcon - Detect MouseOut

使用这个类,你可以像这样检索托盘的 Rectangle Structure :

Rectangle trayRectangle = WinAPI.GetTrayRectangle();

这将为您提供托盘的顶部、左侧、右侧和底部坐标以及其宽度和高度。

我已经包括了下面的类(class):
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));
    }
}

希望这可以帮助。

关于c# - 在单击的通知图标上方放置表单,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/7294878/

10-17 02:49