在图片框

时间:2016-03-21 15:18:21

标签: c# picturebox

我试图在图片框中移动形状时遇到问题,选中时形状正确移动,但是被困在一个小区域中,我无法在整个图片框中移动它。我想知道我的问题是在paint事件还是move事件中,因为在整个图片框中绘制形状时我没有问题。

以下是代码:

    private void pictureBox1_MouseMove(object sender, MouseEventArgs e)
    {
        if (e.Button == MouseButtons.Left)
        {
                pictureBox1.Cursor = Cursors.Hand;

                MyPoint tempPtDep = new MyPoint(e.X, e.Y);
                ((Shape)listBox1.SelectedItem).gsPtAcc = new MyPoint(
                      Math.Min(ptdep.x, tempPtDep.x),
                      Math.Min(ptdep.y, tempPtDep.y));

                pictureBox1.Invalidate();
        }
    }

    private void pictureBox1_Paint(object sender, PaintEventArgs e)
    {

        if (shapeList != null)
        {
            Graphics g = e.Graphics;
            foreach (Shape elem in shapeList)
            {
                if(elem.Equals(listBox1.SelectedItem as Shape))
                {

                    pen = new Pen(Color.RoyalBlue, 3);
                    pen.DashStyle = System.Drawing.Drawing2D.DashStyle.Dash;
                }
                else
                    pen = new Pen(elem.Couleur, 3);


                if (elem is Segment)
                {
                    seg = elem as Segment;
                    seg.WDraw(g, pen, seg.gsPtAcc);
                }
                else if (elem is Circle)
                {
                    cercle = elem as Circle;
                    cercle.WDraw(g, pen, cercle.gsPtAcc);
                }
                else if (elem is Square)
                {
                    carre = elem as Square;
                    carre.WDraw(g, pen, carre.gsPtAcc);
                }
            }
        }            
    }

0 个答案:

没有答案