Pregunta

¿Cómo fuerzo un menú contextual para que se muestre un icono de bandeja cuando se hace clic en lugar de hacer clic con el botón derecho?

He intentado usar el evento MouseClick, pero los Eventargs tienen la posición del mouse en x0y0.

¿Fue útil?

Solución

Esto debería hacerlo por usted:

private void notifyIcon1_Click(object sender, EventArgs e)
        {
            contextMenuStrip1.Show(Cursor.Position.X, Cursor.Position.Y);
        }

Otros consejos

Un método alternativo que he encontrado que funciona un poco mejor:

private void notifyIcon1_MouseUp(object sender, MouseEventArgs e)
    {
        if (e.Button == MouseButtons.Left)
        {
            System.Reflection.MethodInfo mi = typeof(NotifyIcon).GetMethod("ShowContextMenu", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic);
            mi.Invoke(notifyIcon1, null);
        }
    }
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top