gpt4 book ai didi

c# - 菜单项出现在任务栏上而不是上面

转载 作者:太空宇宙 更新时间:2023-11-03 11:38:07 24 4
gpt4 key购买 nike

我正在使用 C# 手动将通知图标添加到基于表单的应用程序的任务栏。菜单添加正常,但是当我右键单击该图标时,列表默认显示在任务栏下方。如何让它出现在您通常期望的位置?

NotifyIcon notfiyIcon = new NotifyIcon();
ContextMenu contextMenu = new ContextMenu();
MenuItem menuItem = new MenuItem();

menuItem.Text = "Exit";
menuItem.Click += new System.EventHandler(this.btnLogOut_Click);

contextMenu.MenuItems.Add(menuItem);
contextMenu.MenuItems.Add("hello");
notfiyIcon.ContextMenu = contextMenu;

notfiyIcon.Text = "Property Sales";

Icon icon = new Icon("icon.ico");
notfiyIcon.Icon = icon;

notfiyIcon.Visible = true;

enter image description here

这是我希望它出现的地方。

enter image description here

最佳答案

这是 Windows 上下文菜单的预期行为。

通常,上下文菜单从鼠标位置向下打开,这就是您在第一个屏幕截图中看到的。在您的第二个屏幕截图中,上下文菜单太高而无法向下打开(它会延伸出屏幕),因此它从鼠标位置向上打开以便完全可见。

您可以手动设置菜单位置,但为了保持一致性,不建议这样做。

关于c# - 菜单项出现在任务栏上而不是上面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5585162/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com