コード例 #1
0
        public void Draw(Graphics g)
        {
            g.PageUnit  = GraphicsUnit.Millimeter;
            g.PageScale = 1.0F;

            Pen lePen = new Pen(Color.Red, 0.01F);



            g.TranslateTransform(this.pictureBox1.Location.X + 1, this.pictureBox1.Location.Y + (float)YMax - 1 /* this.pictureBox1.Size.Height - 1*/);

            if (YMin < 0)
            {
                g.TranslateTransform(0, -(int)Math.Abs(YMin));                                          //transforms point-of-origin to the lower left corner of the canvas.
            }
            if (XMin < 0)
            {
                g.TranslateTransform((int)Math.Abs(XMin), 0);
            }

            //g.SmoothingMode = SmoothingMode.AntiAlias;


            g.DrawEllipse(lePen, 5, 5, 20, 20);

            foreach (DrawingObject obj in objectIdentifier)                                                     //iterates through the objects
            {
                switch (obj.shapeType)
                {
                case 2:                                                 //line
                {
                    Line temp = (Line)drawingList[obj.indexNo];

                    lePen.Color = temp.AccessContourColor;
                    lePen.Width = temp.AccessLineWidth;


                    highlightedRegion.Location = new Point((int)temp.GetStartPoint.X, (int)temp.GetStartPoint.Y);

                    highlightedRegion.Width  = (int)(temp.GetStartPoint.X - temp.GetEndPoint.X);
                    highlightedRegion.Height = (int)(temp.GetStartPoint.Y - temp.GetEndPoint.Y);

                    if (mainScale == 0)
                    {
                        mainScale = 1;
                    }

                    temp.Draw(lePen, g, mainScale);

                    break;
                }

                case 3:                                                 //rectangle
                {
                    rectangle temp = (rectangle)drawingList[obj.indexNo];

                    lePen.Color = temp.AccessContourColor;
                    lePen.Width = temp.AccessLineWidth;


                    temp.Draw(lePen, g);

                    break;
                }

                case 4:                                                 //circle
                {
                    circle temp = (circle)drawingList[obj.indexNo];

                    lePen.Color = temp.AccessContourColor;
                    lePen.Width = temp.AccessLineWidth;

                    if (mainScale == 0)
                    {
                        mainScale = 1;
                    }

                    temp.Draw(lePen, g, mainScale);

                    break;
                }

                case 5:                                                 //polyline
                {
                    polyline temp = (polyline)drawingList[obj.indexNo];

                    lePen.Color = temp.AccessContourColor;
                    lePen.Width = temp.AccessLineWidth;

                    if (mainScale == 0)
                    {
                        mainScale = 1;
                    }

                    temp.Draw(lePen, g, mainScale);

                    break;
                }

                case 6:                                                 //arc
                {
                    arc temp = (arc)drawingList[obj.indexNo];

                    lePen.Color = temp.AccessContourColor;
                    lePen.Width = temp.AccessLineWidth;

                    if (mainScale == 0)
                    {
                        mainScale = 1;
                    }

                    temp.Draw(lePen, g, mainScale);

                    break;
                }
                }
            }


            //	g.Dispose();		//not disposed because "g" is get from the paintbackground event..
            lePen.Dispose();
        }