代码如下 如果要拖动他 需要加什么代码 
        private void pictureBox1_Paint(object sender, PaintEventArgs e)
        {
            System.Drawing.Graphics formGraphics = e.Graphics; 
            string drawString = "Text";
            System.Drawing.Font drawFont = new System.Drawing.Font("Arial", 16);
            System.Drawing.SolidBrush drawBrush = new System.Drawing.SolidBrush(System.Drawing.Color.Black);
            float x = 250.0f;
            float y = 200.0f;
            System.Drawing.StringFormat drawFormat = new System.Drawing.StringFormat(StringFormatFlags.DirectionVertical);//文本
            formGraphics.DrawString(drawString, drawFont, drawBrush, x, y);//绘制文本        }

解决方案 »

  1.   

    MouseDown的时候记录下初始坐标,MouseMove的时候若鼠标按键按着,那么计算当前坐标和初始坐标之差,
    然后重绘你的图,只是x,y都加上刚才求出的便宜量。请用双倍缓冲方式,否则picturebox的图像会有闪烁的现象。
      

  2.   

    可是我绘制了好几个 文本 怎么去知道 要拖动的是那个? MOUSE down 怎么知道他点的是哪个文本?
      

  3.   

    你每次画文本的时候,都记录下他们所在区域。
    MouseDown的时候,有当前鼠标坐标,去你记录的区域里找包含你鼠标当前坐标的对象。找到之后就知道该拖哪个了。其实,只是文字的话,用Label也可以,拖动的话,google一下如何拖动控件。那样更方便些
      

  4.   


    MouseMove事件里添加pictureBox1.Invalidate();
    等我上IE
      

  5.   


        public partial class Form1 : Form
        {
            int x,y,a, b,c,d;
            bool isPressDown;
            public Form1()
            {
                InitializeComponent();
                this.DoubleBuffered = true;
            }        private void Form1_Load(object sender, EventArgs e)
            {        }
            private void pictureBox1_Paint(object sender, PaintEventArgs e)
            {
                System.Drawing.Graphics formGraphics = e.Graphics;
                string drawString = "Text";
                System.Drawing.Font drawFont = new System.Drawing.Font("Arial", 16);
                System.Drawing.SolidBrush drawBrush = new System.Drawing.SolidBrush(System.Drawing.Color.Black);
                //float x = 250.0f;
                //float y = 200.0f;
                if (x+a > 700)
                {
                    x -= 700;
                }
                else if (x+a < 0)
                {
                    x += 700;
                }
                if (y+b > 500)
                {
                    y -= 500;
                }
                else if (y+b < 0)
                {
                    y += 500;
                }
                System.Drawing.StringFormat drawFormat = new System.Drawing.StringFormat(StringFormatFlags.DirectionVertical);//文本 
                formGraphics.DrawString(drawString, drawFont, drawBrush, x+a, y+b);//绘制文本         }        private void pictureBox1_MouseMove(object sender, MouseEventArgs e)
            {
                if (isPressDown)
                {
                    a = e.X-c;
                    b = e.Y-d;
                    pictureBox1.Invalidate();
                }
            }        private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
            {
                isPressDown = true;
                c = e.X;
                d = e.Y;            
            }        private void pictureBox1_MouseUp(object sender, MouseEventArgs e)
            {
                isPressDown = false;
                x += a;
                y += b;
                pictureBox1.Invalidate();
                a = b = c = d = 0;
            }
        }
      

  6.   

    没有实现多个文本,这是整个pictureBox拖动,即使没有点到文本也会动,可以Panel+多个label拖动,想起遇到的一个问题,写了这么一段彪呼呼的        private void Form1_MouseDown(object sender, MouseEventArgs e)
            {
                if ((e.X > panel1.Location.X) && (e.Y > panel1.Location.Y) && (e.X < panel1.Location.X + panel1.Size.Width) && (e.Y < panel1.Location.Y + panel1.Height))
                {
                    MessageBox.Show(" hit");
                }
                else
                {
                    MessageBox.Show(" miss");
                }
            }永远不会hit,满足hit条件时Form1接收不到事件,因为有个视频控件,没有mousedown事件,我想判断其是否被点中,一直没解决,后来用不到了,没再寻找.
    有没有办法让被盖住的也接收到事件?
    嘿嘿,菜