C# - 在上下文菜单之前触发 "right click" 事件

C# - Trigger "right click" event before context menu

我想做的是 select 在上下文菜单显示之前右击列表框中的一个项目。

我看到顺序不是这样的:先弹出上下文菜单,处理后触发右键事件。

这是我的列表框(及其关联的上下文菜单): https://i.gyazo.com/b2b2d7d5f8094db9c7e62565df2cafb9.png

这将是我的右键单击事件:

private void listBox1_MouseClick(object sender, MouseEventArgs e)
    {
        if (e.Button == MouseButtons.Right)
        {
            listBox1.SelectedIndex = listBox1.IndexFromPoint(e.X, e.Y);
        }
    }

我看过很多帖子,但是none真正解释了如何管理事件触发的顺序。

@Panagiotis Kanavos:"Use the MouseDown, not the MouseClick event. A MouseClick event is raised when both MouseDown and MouseUp events are received by your application."

这就成功了:)