我的form里面有个panel,我希望实现的功能是当鼠标点击左键的时候鼠标变成小手的样子并且移动鼠标可以移动panel,就像看图片那种功能。请教大侠们,我这个是写在那个方法里哦??是写在MouseDown事件里还是写在MouseMove事件里面哦??望解答,在此先谢谢先。

解决方案 »

  1.   

    在MouseDown事件里把Cursor属性设为Hand,出来的效果就是小手
      

  2.   

    你点form 然后在form属性里头有个cursor 把它选成hand 就行了
      

  3.   

    在form的mousemove消息里面操作
    mousemove要检查mousedown是否按下 还是检查mouseup是否弹起了
      

  4.   

    做一个全局
    private int x = 0;
    private int y = 0;
    然后你应该在鼠标MouseDown里写 
    this.Cursor = Cursors.Hand 
    x = e.X;
    y = e.Y;然后在MouseMove里写
    if(this.Cursor == Cursors.Hand )
    {
        //变换坐标
        int distanceX = e.X - panel.location.X;
        int distanceY = e.Y - panel.location.Y;
        panel.location = new Point(panel.Location.X + x, panel.Location.Y + y);
    }
      

  5.   

    在MouseDown事件里设置鼠标样式,在mousemove事件里获取鼠标位置,设置panel位置
    this.MouseDown += new System.Windows.Forms.MouseEventHandler(MyMouseDown);
                this.MouseLeave += new System.EventHandler(MyMouseLeave);
                this.MouseMove += new System.Windows.Forms.MouseEventHandler(MyMouseMove);
    private void MyMouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
            {
               int x = e.X;
            }
    private void MyMouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
        {
         }
      

  6.   

    我写错了 应该这样
    //变换坐标 
        int distanceX = e.X - x; 
        int distanceY = e.Y - y; 
        panel.location = new Point(panel.Location.X + distanceX , panel.Location.Y + distanceY ); 
      

  7.   

    //变换坐标 
        int distanceX = e.X - x; 
        int distanceY = e.Y - y; 
        panel.location = new Point(panel.Location.X + distanceX , panel.Location.Y + distanceY ); 再加个
    x = e.X;
    y = e.Y;
    这样就好了
      

  8.   


    做一个全局 
    private int x = 0; 
    private int y = 0; 
    然后你应该在鼠标MouseDown里写 
    this.Cursor = Cursors.Hand 
    x = e.X; 
    y = e.Y; 然后在MouseMove里写 
    if(this.Cursor == Cursors.Hand ) 

        //变换坐标 
        int distanceX = e.X - x; 
        int distanceY = e.Y - y; 
        panel.location = new Point(panel.Location.X + distanceX , panel.Location.Y + distanceY );     x = e.X; 
        y = e.Y; 
    }
      

  9.   

    private void panel1_MouseDown(object sender, MouseEventArgs e)
            {
                panel1.MouseMove += new MouseEventHandler(panel1_MouseMove);
                panel1.Cursor = Cursors.Hand;
            }        void panel1_MouseMove(object sender, MouseEventArgs e)
            {
                //这里改变你panel的位置
            }        private void panel1_MouseUp(object sender, MouseEventArgs e)
            {
                panel1.MouseMove -= new MouseEventHandler(panel1_MouseMove);
                panel1.Cursor = Cursors.Default;
            }       
    如果你想鼠标移到那panel上,光标就变,那这个换到panel1.Cursor 放到 MouseEnter 和MouseLeave里面改变。