Ejemplo n.º 1
0
 private void draw(Graphics g)
 {
     foreach (TextObject text in textList)
     {
         Brush brush = new SolidBrush(text.color);
         g.DrawString(text.text, text.font, (Brush)brush, text.pos);
     }
     foreach (PolygonObject polygon in polygonList)
     {
         g.DrawPolygon(polygon.pen, polygon.list.ToArray());
     }
     if (startPoint != Point.Empty && currentPoint != Point.Empty)
     {
         switch (mode)
         {
             case Mode.SELECT:
                 break;
             case Mode.DRAW:
                 PolygonObject poly = new PolygonObject();
                 poly.rectangle(startPoint, currentPoint);
                 g.DrawPolygon(pen, poly.list.ToArray());
                 break;
             case Mode.LINE:
                 g.DrawLine(pen, startPoint, currentPoint);
                 break;
             case Mode.TEXT:
                 break;
         }
     }
 }
Ejemplo n.º 2
0
        private void pictureBox_MouseUp(object sender, MouseEventArgs e)
        {
            textBoxOffFocused();
            bool moved = false;
            switch (mode)
            {
                case Mode.SELECT:

                    for (int i = 0; i < polygonList.Count(); i++)
                    {
                        GraphicsPath path = new GraphicsPath();
                        path.AddPolygon(polygonList[i].list.ToArray());
                        Region region = new Region(path);
                        Graphics g = CreateGraphics();
                        RectangleF bound=region.GetBounds(g);
                        if (g!=null && bound!=null && bound.Contains(startPoint))
                        {
                            polygonList[i].shift(e.Location.X - startPoint.X, e.Location.Y - startPoint.Y);
                            moved = true;
                        }
                    }
                    if (!moved)
                    {
                        int dx, dy;
                        for (int i = 0; i < textList.Count(); i++)
                        {
                            SizeF sizeF = pictureBox.CreateGraphics().MeasureString(textList[i].text, textList[i].font);
                            Rectangle rb = new Rectangle(textList[i].pos.X, textList[i].pos.Y, (int)sizeF.Width, (int)sizeF.Height);
                            if (rb.Contains(startPoint))
                            {
                                dx = e.Location.X - startPoint.X;
                                dy=e.Location.Y - startPoint.Y;
                                if(0<=textList[i].pos.X + dx)
                                    textList[i].pos.X += dx;
                                if (0 <= textList[i].pos.Y + dy)
                                    textList[i].pos.Y += dy;
                            }
                        }
                    }
                    break;
                case Mode.DRAW:
                    PolygonObject poly = new PolygonObject();
                    poly.rectangle(startPoint, e.Location);
                    poly.setPen(pen);
                    polygonList.Add(poly);
                    break;
                case Mode.TEXT:
                    if (!textBox.Visible)
                    {
                        textBox.Location = e.Location;
                        textBox.Show();
                    }
                    break;
                case Mode.LINE:
                    PolygonObject polygon = new PolygonObject();
                    polygon.addPoint(startPoint);
                    polygon.addPoint(e.Location);
                    polygon.setPen(pen);
                    polygonList.Add(polygon);
                    break;
            }
            startPoint = Point.Empty;
            Refresh();
        }