c# ListBox 问题

wsy6bxw 2011-01-16 06:06:30
大家好! 小弟遇到了个问题,C# 的ListBox实现右键菜单,里面的项是动态添加的,当出现滚动条时,我的处理方式就出问题了。 代码如下
  //鼠标右击的时候
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));
}
}

}


请问有滚动条时我该如何解决右键菜单定位不准的问题? 谢谢!
...全文
80 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
ningweidong 2011-03-31
  • 打赏
  • 举报
回复
那就不要用右键菜单,只用左键处理
我TM真的是猪 2011-03-30
  • 打赏
  • 举报
回复
什么情况啊?想要实现的是什么功能捏?
子夜__ 2011-03-23
  • 打赏
  • 举报
回复
龍月 2011-03-21
  • 打赏
  • 举报
回复
你想实现什么了??

1,977

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 其他语言讨论
社区管理员
  • 其他语言社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧