当前位置:编程学习 > C#/ASP.NET >>

各位大侠,帮小弟解决一个问题........(在线等待)

下面为一段按钮移动的程序,但是有点问题. 希望大家给个帮助.
        1. 我怎么样才能够将所有的控件都能移动呢.
         因为我的下面程序只能移动最后一个点出来的控件.       
     
        Button a = new Button();
        private Point downPoint;
        private Rectangle downRectangle;
        private Rectangle lastRectangle;
        int buttonindex = 0;
        private void button1_Click(object sender, EventArgs e)
        {
            Button b = new Button();
            b.Parent = this;
            b.Text = "button" + buttonindex;
            buttonindex++;
            panel1.Controls.Add(b);
            b.MouseDown += new MouseEventHandler(b_MouseDown);
            b.MouseMove += new MouseEventHandler(b_MouseMove);
            b.MouseUp += new MouseEventHandler(b_MouseUp);
            a = b;
        }
  
        private void b_MouseDown(object sender, MouseEventArgs e)
        {
            if (e.Button != MouseButtons.Left) return;
            downPoint = e.Location;
            lastRectangle =
             new Rectangle(0, 0, a.Width, a.Height);
            downRectangle.Offset(((Control)sender).PointToScreen(new   Point(0, 0)));
            ControlPaint.DrawReversibleFrame(
                downRectangle, Color.White, FrameStyle.Thick);
            lastRectangle = downRectangle;
        }

        private void b_MouseMove(object sender, MouseEventArgs e)
        {
            if (e.Button != MouseButtons.Left) return;
            ControlPaint.DrawReversibleFrame(
                downRectangle, Color.White, FrameStyle.Thick);

            Rectangle rectangle = downRectangle;
            rectangle.Offset(e.X - downPoint.X, e.Y - downPoint.Y);
            ControlPaint.DrawReversibleFrame(
                rectangle, Color.White, FrameStyle.Thick);
            lastRectangle = rectangle;
        }

        private void b_MouseUp(object sender, MouseEventArgs e)
        {
            if (e.Button != MouseButtons.Left) return;
            ControlPaint.DrawReversibleFrame(
                lastRectangle, Color.White, FrameStyle.Thick);
            a.Location = new Point(
                 ((Control)sender).Location.X + e.X - downPoint.X,
                  ((Control)sender).Location.Y + e.Y - downPoint.Y);
        } --------------------编程问答-------------------- 大家帮顶一下的啦./
补充:.NET技术 ,  C#
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,