小弟做了一个按钮鼠标经过停留后出现菜单
现在想让菜单在光标离开后自动消失
于是:
  private void button1_MouseHover(object sender, EventArgs e)
        {
            this.contextMenuStrip2.Show(709,168);
        } private void contextMenuStrip2_MouseLeave(object sender, EventArgs e)
        {
            this.contextMenuStrip2.Close();
            //this.contextMenuStrip2.Show(709, 168);
            //this.button1
        }
这个 就是菜单contextMenuStrip2
C# 编写
但是现在问题是 这个菜单是有二级菜单的 但是写了这个事件后鼠标离开一级菜单后就消失了 到不了二级菜单 郁闷,居然有这样的问题 微软设计的不行 怎么解决呢? 请各位帮帮忙!

解决方案 »

  1.   

    这些代码估计要自己写了,如果打开了二级菜单,你就要保持菜单存在,否则就消失,逻辑学不上难吧?不知道。net有没有提供这个属性
      

  2.   


    鼠标如果移到有子菜单的项上,在mouseleve的时候就不消失.
      

  3.   

    这个如何控制?,也要写在 mouseleave事件中吗?
      

  4.   

    div中通过onmousemove实现隐藏和显示
    <td class="menu_title" id="menuTitle1“
    onmouseover="this.className='menu_title2';" onclick="menuChange(menu<%=i+1%>,<%=20%>,menuTitle<%=i+1%>);"
    onmouseout="this.className='menu_title';"  height="25">
    判断是否有子集
      

  5.   

    我的是 C#做的winform软件 这样不行
      

  6.   

    经本人研究 后 现贴出代码 祥解csdn:
    private void button1_MouseHover(object sender, EventArgs e)
            {
                //注意坐标计算=屏幕坐标+控件工作区坐标+控件高
                int s = this.Location.X + 59;
                int y = this.Location.Y + 90 + 78;
                this.contextMenuStrip2.Show(s, y);
            }
            private void contextMenuStrip2_MouseLeave(object sender, EventArgs e)
            {
                Point p = new Point(769, 170);
                Point npoin=this.contextMenuStrip2.PointToClient(p);//要将鼠标坐标转化成工作区坐标。
                System.Windows.Forms.ToolStripItem newtool = this.contextMenuStrip2.GetItemAt(npoin);//此处必须使用工作区坐标
                if (newtool != null)
                {
                    if (Cursor.Position.Y < 161 || Cursor.Position.Y > 328 || Cursor.Position.X < 709 || Cursor.Position.X > 900)
                    {
                        this.contextMenuStrip2.Close();
                    }
                }
            }注意红字坐标 这个是要你自己算的 查看一级菜单的水平方向指定坐标处有没有二级菜单,你只要算出大体坐标然后转成工作区坐标就好了(我是用屏幕坐标查看的菜单的坐标,所以才要转换!)。