1
votes

I'm Currently Working in Windows Application.

I just created a tray Icon while closing the Form, Tray Icon is visible in System Tray.

While Left Click the Tray Icon Form is maximized to normal state.

Right Click Event is not working in Release Mode, but working in Debug Mode.

After Building this application Right Event is not working, the output.exe file from Debug mode.

Any help would be appreciated. Thanks in Advance.

In form Load

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);
}

In button close Event

   private void btnClose_Click(object sender, EventArgs e)
{
    this.WindowState = FormWindowState.Minimized;
    TrayIcon.Visible = true;
    ShowInTaskbar = false;
}

In Tray Icon mouse click Event

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);
    }
}

Tray Menu dispose event

private void Dispose_Click(object Sender, EventArgs e)
{
    TrayIcon.Visible = false;
    TrayIcon.Icon = null;
    TrayIcon.Dispose();
    Application.Exit();
}

While in Release Mode Tray Icon Mouse Right Click Event is not working . But in Debug Mode its working.

Please Help me to solve this Issue.

1
What type is TrayMenu? It ain't ContextMenu (which does not have a Show(int, int) method)... - user2819245
@elgonzo Presumably ContextMenuStrip - Sriram Sakthivel
@ elgonzo: i tried even TrayMenu.Show(); and TrayMenu.Visible=true; also . Its not working - Ganesh Pravin
@elango can u be more specific. - Ganesh Pravin
@Ganesh, sorry, stupid me. Somehow i managed not to see you are using Cursor.Position. I am embarrassed :) - user2819245

1 Answers

0
votes

Maybe this is a dumb answer, but are you sure your release build is up to date? If your debugging in the designer then the release build isn't updated when you run a Build unless you set it up that way. Maybe your release build is from before you added code to handle the right click?

If its not that, does the release build work if you run it from the Release folder rather than debugging in release mode from the designer?