1,977
社区成员
![](https://csdnimg.cn/release/cmsfe/public/img/topic.427195d5.png)
![](https://csdnimg.cn/release/cmsfe/public/img/me.40a70ab0.png)
![](https://csdnimg.cn/release/cmsfe/public/img/task.87b52881.png)
![](https://csdnimg.cn/release/cmsfe/public/img/share-circle.3e0b7822.png)
//鼠标右击的时候
private void listunit_MouseDown(object sender, MouseEventArgs e)
{
//如果当前的试卷不为篇章
if (Curpaperstyle!=paper.chapter)
{
this.listunit.ContextMenuStrip = null;
return;
}
if (e.Button == MouseButtons.Right)
{
int listBoxItemToTalHeight = listunit.Items.Count * listunit.ItemHeight;
int currentIndex = e.Y / 12;
string mousey = string.Format("{0}", e.Y);
//测试用输出
Console.WriteLine(mousey);
if (e.Y > listBoxItemToTalHeight)
{
this.listunit.ContextMenuStrip = null;
return;
}
else
{
this.listunit.ContextMenuStrip = this.contextMenuStrip1;
contextMenuStrip1.Visible = true;
if (listunit.SelectedItem != null && currentIndex != listunit.SelectedIndex)
{
this.listunit.SetSelected(listunit.SelectedIndex, false);
}
SelectIndex = currentIndex;
this.listunit.SetSelected(currentIndex, true);
this.listunit.ContextMenuStrip.Show(listunit, new Point(e.X, e.Y));
}
}
}