Home > front end >  Hide dummy taskbar icon for notification icon context menu
Hide dummy taskbar icon for notification icon context menu

Time:11-17

I have a simple .Net 5.0 WinForm form which is automatically hidden after the application started:

private void form_Shown (object sender, EventArgs e)
{
    Hide ();
}

It only creates a notify icon. This notify icon has a context menu strip that is shown by a left mouse click:

private void notifyIcon_Click (object sender, EventArgs e)
{
    contextMenuStrip.Show (MousePosition);
}

This works fine, but as long as the context menu strip is visible, a dummy taskbar icon appears:

enter image description here

This doesn't happen if the form is not hidden or the context menu strip is shown by a right mouse click (via ContextMenuStrip property).

How can I prevent this icon?

CodePudding user response:

I finally found a solution myself:

[DllImport ("user32.dll", CharSet = CharSet.Auto, ExactSpelling = true)]
private static extern bool SetForegroundWindow (HandleRef hWnd);

private void notifyIcon_Click (object sender, EventArgs e)
{
    SetForegroundWindow (new HandleRef (notifyIcon.ContextMenuStrip, notifyIcon.ContextMenuStrip.Handle));
    notifyIcon.ContextMenuStrip.Show (MousePosition);
}

CodePudding user response:

Try Me.Hide()

lets see the outcome

Try assign your context menu to the notifyicons .ContextMenu property like and use the notifyicons .Visible property to show it instead of using the .Show method.

  • Related