【发布时间】:2013-11-15 08:16:24
【问题描述】:
我目前在 Windows 应用程序中工作。
我刚刚在关闭表单时创建了一个托盘图标,托盘图标在系统托盘中可见。
左键单击时托盘图标窗体最大化为正常状态。
右键单击事件在发布模式下不工作,但在调试模式下工作。
构建此应用程序后右事件不起作用,从调试模式输出.exe文件。
任何帮助将不胜感激。 提前致谢。
在表单加载
private void MainRelease_Load(object sender, EventArgs e)
{
TrayIcon.Visible = false;
TrayMenu.Items.Add("Exit");
TrayMenu.Items[0].Click += new System.EventHandler(this.Dispose_Click);
}
在按钮关闭事件中
private void btnClose_Click(object sender, EventArgs e)
{
this.WindowState = FormWindowState.Minimized;
TrayIcon.Visible = true;
ShowInTaskbar = false;
}
在托盘图标鼠标点击事件
private void TrayIcon_MouseClick(object sender, MouseEventArgs e)
{
if (e.Button == System.Windows.Forms.MouseButtons.Left)
{
this.WindowState = FormWindowState.Normal;
TrayIcon.Visible = false;
ShowInTaskbar = true;
}
if (e.Button == System.Windows.Forms.MouseButtons.Right)
{
TrayMenu.Show(Cursor.Position.X, Cursor.Position.Y);
}
}
托盘菜单处置事件
private void Dispose_Click(object Sender, EventArgs e)
{
TrayIcon.Visible = false;
TrayIcon.Icon = null;
TrayIcon.Dispose();
Application.Exit();
}
在释放模式下托盘图标鼠标右键单击事件不起作用。但在调试模式下它可以工作。
请帮我解决这个问题。
【问题讨论】:
-
TrayMenu 是什么类型的?它不是 ContextMenu(它没有 Show(int, int) 方法)...
-
@elgonzo 大概是 ContextMenuStrip
-
@elgonzo:我什至尝试过 TrayMenu.Show();和 TrayMenu.Visible=true;还 。它不工作
-
@elango 你能说得更具体点吗。
-
@Ganesh,对不起,愚蠢的我。不知何故,我设法没有看到您正在使用 Cursor.Position。我很尴尬:)
标签: c# windows system-tray trayicon