DuckFterminal
DuckFterminal

Reputation: 149

How to Show ContextMenuStrip Above the Mouse Postion?

I'm trying make a contextMenuStrip with Notify Icon, But I can't put the location of this Context above the mouse Position. it's show at same position mouse

Context menu strip position Image

private void ntfy2_MouseClick(object sender, MouseEventArgs e)
{
    if (e.Button == MouseButtons.Right)
    {
        contextMenuStrip1.Show(Cursor.Position.X, Cursor.Position.Y); //Show at Postion Mouse
    }
}

Upvotes: 2

Views: 151

Answers (1)

Prochu1991
Prochu1991

Reputation: 453

Does this code help you?

private void ntfy2_MouseClick(object sender, MouseEventArgs e)
{
    if (e.Button == MouseButtons.Right)
    {
                var relativeClickedPosition = e.Location;
        var screenClickedPosition = (sender as Control).PointToScreen(relativeClickedPosition);
        contextMenuStrip1.Show(screenClickedPosition);
    }
}

@DuckFterminal if my post helped you enough, please click on bird of acceptance, ok? :)

Upvotes: 1

Related Questions