我按照网上查找的代码写进去后,为什么还是不能实现拖动?

解决方案 »

  1.   

    namespace WindowsFormsApplication5
    {
        public partial class Form1 : Form
        {
            Point p1=new Point();
            bool drag = false;
            public Form1()
            {
                InitializeComponent();
            }        private void Form1_MouseDown(object sender, MouseEventArgs e)
            {
                if (e.Button == MouseButtons.Left)
                {
                    p1.X = e.X;
                    p1.Y = e.Y;
                    //drag = true;
                }
            }
            private void Form1_MouseMove(object sender, MouseEventArgs e)
            {
                //if (drag == true)
                //{
                    if (e.Button == MouseButtons.Left)
                    {
                        this.Left = Control.MousePosition.X - p1.X - SystemInformation.FrameBorderSize.Width;
                        this.Top = Control.MousePosition.Y - p1.Y - SystemInformation.FrameBorderSize.Height - SystemInformation.CaptionHeight;
                    }
                //}
            }
            private void Form1_MouseUp(object sender, MouseEventArgs e)
            {
                drag = false;
            }
        }
    }
    这样试着可以