现有一个Form 
添加一个picturebox 设置为dock=fill
鼠标点击picturebox实现窗体的拖动该怎么做?
注意:
下面这个函数已经不管用了,因为picturebox已经覆盖了form
  protected override void WndProc(ref System.Windows.Forms.Message m)
        {
            switch (m.Msg)
            {
                case WM_NCHITTEST:
                    base.WndProc(ref m);
                    if (m.Result == (IntPtr)HTCLIENT)
                    {
                        m.Result = (IntPtr)HTCAPTION;
                    }
                    break;
                default:
                    base.WndProc(ref m);
                    break;
            }
        }[/color]

解决方案 »

  1.   

            private Point mouseOffset;
            private bool isMouseDown = false;        private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
            {
                if (e.Button == MouseButtons.Left)
                {
                    mouseOffset = new Point(-e.X, -e.Y);
                    isMouseDown = true;
                }
            }        private void pictureBox1_MouseMove(object sender, MouseEventArgs e)
            {
                if (isMouseDown)
                {
                    Point mousePos = Control.MousePosition;
                    mousePos.Offset(mouseOffset.X, mouseOffset.Y);
                    this.Location = mousePos;
                }
            }        private void pictureBox1_MouseUp(object sender, MouseEventArgs e)
            {
                if (e.Button == MouseButtons.Left)
                {
                    isMouseDown = false;
                }
            }
      

  2.   

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Text;
    using System.Windows.Forms;
    using System.Runtime.InteropServices;
    namespace WindowsApplication1
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }
            [DllImport("user32.dll", EntryPoint = "SendMessage")]
            public static extern int SendMessage(IntPtr hWnd, int wMsg, int wParam, int lParam);
            [DllImport("user32.dll", EntryPoint = "ReleaseCapture")]
            public static extern int ReleaseCapture();
            public const int WM_SysCommand = 0x0112;
            public const int SC_MOVE = 0xF012;
           
        
           
            private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
            {
                ReleaseCapture();
                SendMessage(this.Handle, WM_SysCommand, SC_MOVE,0 );
            }
        }
    }