窗体有一些控件:Form -> Dock Fill Panel-> Dock Left Label -> Dock Fill Label.现在我想判断鼠标是否在窗体之上,请问该怎么解决呢?
有没有简单的方法?简单的MouseEnter/MouseLeave是没有用的。

解决方案 »

  1.   

    Form -> Dock Fill Panel-> Dock Left Label
                           -> Dock Fill Label结构应该是这样
      

  2.   

    那不是每一个控件都要 MouseMove?该死的空格:
    Form -> Dock Fill Panel-> Dock Left Label
    ------------------------> Dock Fill Label
      

  3.   

    用timer吧        [DllImport("user32.dll")]
            private static extern bool GetCursorPos(out Point p);        private void timer1_Tick(object sender, EventArgs e)
            {
                Point p;
                GetCursorPos(out p);
                if (p.X >= this.Left && p.X <= this.Right && p.Y >= this.Top && p.Y <= this.Bottom)
                {
                    MessageBox.Show("ok");
                }
            }
      

  4.   

    Timer timer = new Timer();
    public Form1()
    {
        InitializeComponent();    timer.Interval = 50;
        timer.Tick += delegate
        {
            double opacity = this.Bounds.Contains(Cursor.Position) ? 0.9 : 0.4;
            if( this.Opacity != opacity ) this.Opacity = opacity;
        };
        timer.Start();
    }
      

  5.   

    我也有考虑一个 timer,但是最终还是否决了。
    觉得这个是“不行中的办法”。
      

  6.   

    木办法了吗~以前也有google类似的问题,但最终是没有答案。
      

  7.   

    应该不难吧,通过 MousePosition获得鼠标相对于屏幕的坐标,再通过窗体的位置和大小获得窗体的矩形区域,看鼠标坐标是否在其中不就行了吗?
      

  8.   

     int xl = 0;
            int yl = 0;
            private void timer1_Tick(object sender, EventArgs e)
            {
                xl = MousePosition.X;
                yl = MousePosition.Y;
                if (xl < this.Location.X + this.Width && xl > this.Location.X)
                {
                    if (yl > this.Location.Y && yl < this.Location.Y + this.Height)
                    {
                        this.Opacity = 1;
                    }
                    else 
                    {
                        this.Opacity = 0.5;
                    }
                }
                else
                {
                    this.Opacity = 0.5;
                }
            }试了下 ,确实可以的