我想要让一个PictureBox控件跟随着鼠标移动,可以实现吗?有没有什么简单的方法?

解决方案 »

  1.   

    最简单的有效的方法,请你记得给我分。private void Form1_MouseMove(object sender, MouseEventArgs e)
            {
                this.pictureBox1.Location = new Point(e.X, e.Y);
            }
      

  2.   

    参看
    http://blog.csdn.net/knight94/archive/2006/04/14/663089.aspx这里面是窗体随着鼠标移动,你进行修改即可。
      

  3.   

    楼上的方法在鼠标移到其它控件上时就无效了。
    要先Capture 或者 重载消息处理函数
      

  4.   

    在mousedown,mousemove,mouseup三个事件里进行处理,改变控件的location就OK了
    private bool blnState=false; private void Form1_MouseDown(object sender, MouseEventArgs e)
    {
    blnState=true;
    ox=e.X;
    oy=e.Y; }
    int ox=0;
    int oy=0;
    private void Form1_MouseMove(object sender, MouseEventArgs e)
    { try
    {
    if(blnState)
    {
    this.Location =new Point(this.Location.X-(ox-e.X),this.Location.Y-(oy-e.Y) );
    }
    }
    catch(Exception ex)
    {
    MessageBox.Show(ex.Message );
    }
    } private void Form1_MouseUp(object sender, MouseEventArgs e)
    {
    blnState=false; }
      

  5.   

    咦,对哦,就像coowoo说的那样,当鼠标进入其它控件时就不行了,谁有什么好的解决方法吗?
      

  6.   

    private bool blnState=false; private void Form1_MouseDown(object sender, MouseEventArgs e)
    {
    blnState=true;
    ox=e.X;
    oy=e.Y; }
    int ox=0;
    int oy=0;
    private void Form1_MouseMove(object sender, MouseEventArgs e)
    { try
    {
    if(blnState)
    {
    this.Location =new Point(this.Location.X-(ox-e.X),this.Location.Y-(oy-e.Y) );
    }
    }
    catch(Exception ex)
    {
    MessageBox.Show(ex.Message );
    }
    } private void Form1_MouseUp(object sender, MouseEventArgs e)
    {
    blnState=false; }
      

  7.   

    唉,算了,这个贴就当送份贴吧,说话要算数,送分。
    我新开了一个帖子,还是关于这个问题,谁进来帮忙解决一下。谢谢
    http://community.csdn.net/Expert/topic/4755/4755759.xml?temp=.7238733
      

  8.   

    利用消息循环来处理:       
     private const int WM_MOUSEMOVE = 0x0200;
            protected override void WndProc(ref Message m)
            {
                if (m.Msg == WM_MOUSEMOVE)
                {
                    button1.Location = System.Windows.Forms.Cursor.Position;
                }
                base.WndProc(ref m);
            }
    http://www.cnblogs.com/huangliang