C# Tips 2 右键单击listBox时弹出右键菜单并选中单击的行

处理MouseDow事件:

注意:不要设定ListBox的ContextMenu 

 private void lbOutputs_MouseDown(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Right)
            {

                int index = lbOutputs.IndexFromPoint(e.Location);
                if (index >= 0)
                {
                    lbOutputs.SelectedIndex = index;
                    this.deleteMenu.Show(this.lbOutputs,e.Location);
                }
            }
        }

©️2020 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页