コード例 #1
0
        private void DrawComponentLine(int amountOfGateIn, int amountOfGateOut, Rectangle componentRect, LineInOutX inOutX,
                                       Graphics graphics, ComponentEntity currentComponent)
        {
            List <GateNameLocation> currentListOfGateNameLocation = new List <GateNameLocation>();


            Font newFont = new Font("Arial", 9, FontStyle.Regular);

            int stepIn = componentRect.Height / (amountOfGateIn + 1);

            int currentY = componentRect.Top + stepIn;

            foreach (Gate entry in currentComponent.gateIn)
            {
                graphics.DrawLine(Pens.Black, inOutX.startOfLineInX, currentY,
                                  inOutX.endOfLineInX, currentY);

                listOfPointOfLine.Add(new Point((int)inOutX.startOfLineInX, currentY));


                if (entry.dimension > 0)
                {
                    graphics.DrawLine(Pens.Black, inOutX.startOfLineInX + (inOutX.endOfLineInX - inOutX.startOfLineInX) / 2 - 5, currentY + 5,
                                      inOutX.startOfLineInX + (inOutX.endOfLineInX - inOutX.startOfLineInX) / 2 + 5, currentY - 5);

                    graphics.DrawString(entry.dimension.ToString(), newFont, Brushes.Brown,
                                        inOutX.startOfLineInX + (inOutX.endOfLineInX - inOutX.startOfLineInX) / 2 - 5, currentY - 15);
                }



                SizeF newSize = graphics.MeasureString(entry.gateName, newFont);

                int param1 = componentRect.Left + pictureBox1.Width / 30;
                int param2 = currentY - (int)newSize.Height / 2;

                graphics.DrawString(entry.gateName, newFont, Brushes.Brown,
                                    param1, param2);

                GateNameLocation namesLocation = new GateNameLocation(entry, param1, param2,
                                                                      newSize.Width, newSize.Height);

                currentListOfGateNameLocation.Add(namesLocation);

                currentY += stepIn;
            }

            stepIn   = componentRect.Height / (amountOfGateOut + 1);
            currentY = componentRect.Top + stepIn;

            foreach (Gate entry in currentComponent.gateOut)
            {
                graphics.DrawLine(Pens.Black, inOutX.startOfLineOutX, currentY,
                                  inOutX.endOfLineOutX, currentY);

                listOfPointOfLine.Add(new Point((int)inOutX.endOfLineOutX, currentY));

                if (entry.dimension > 0)
                {
                    graphics.DrawLine(Pens.Black, inOutX.startOfLineOutX + (inOutX.endOfLineOutX - inOutX.startOfLineOutX) / 2 - 5, currentY + 5,
                                      inOutX.startOfLineOutX + (inOutX.endOfLineOutX - inOutX.startOfLineOutX) / 2 + 5, currentY - 5);

                    graphics.DrawString(entry.dimension.ToString(), newFont, Brushes.Brown,
                                        inOutX.startOfLineOutX + (inOutX.endOfLineOutX - inOutX.startOfLineOutX) / 2 - 5, currentY - 15);
                }

                SizeF newSize = graphics.MeasureString(entry.gateName, newFont);

                int param1 = componentRect.Left + componentRect.Width - (int)newSize.Width - pictureBox1.Width / 30;
                int param2 = currentY - (int)newSize.Height / 2;


                graphics.DrawString(entry.gateName, newFont, Brushes.Brown,
                                    param1, param2);

                GateNameLocation namesLocation = new GateNameLocation(entry, param1, param2,
                                                                      newSize.Width, newSize.Height);
                currentListOfGateNameLocation.Add(namesLocation);

                currentY += stepIn;
            }

            listForComponentsWithlistOfGateNameLocation.Add(currentListOfGateNameLocation);
        }
コード例 #2
0
        public void DrawComponent(PictureBox pictureBox1, ComponentEntity currentComponent)
        {
            int    pictureBoxWidth  = pictureBox1.Width;
            int    pictureBoxHeight = pictureBox1.Height;
            Bitmap bitmap           = null;

            if (listOfBitmap.Count < 2)
            {
                bitmap   = new Bitmap(pictureBox1.Width, pictureBox1.Height);
                graphics = Graphics.FromImage(bitmap);
            }
            else
            {
                listOfBitmap[listOfPictureBox.IndexOf(pictureBox1)] = new Bitmap(pictureBox1.Width, pictureBox1.Height);
                graphics = Graphics.FromImage(listOfBitmap[listOfPictureBox.IndexOf(pictureBox1)]);
            }

            SolidBrush backGround = new SolidBrush(Color.White);

            SolidBrush circle = new SolidBrush(Color.Black);

            graphics.FillRectangle(backGround, 0, 0, pictureBox1.Width, pictureBox1.Height);


            componentRect = new Rectangle(pictureBox1.Width / 6, pictureBox1.Height / 6,
                                          pictureBox1.Width / 6 * 4, pictureBox1.Height / 6 * 4);

            LineInOutX inOutX = new LineInOutX(0, pictureBox1.Width / 6,
                                               componentRect.Left + componentRect.Width,
                                               pictureBox1.Right);

            Font newFont = new Font("Arial", 9, FontStyle.Regular);

            SizeF newSize = graphics.MeasureString(currentComponent.componentName, newFont);

            graphics.DrawRectangle(Pens.Black, componentRect);


            graphics.DrawString(currentComponent.componentName, newFont, Brushes.Brown,
                                componentRect.Left + componentRect.Width / 2 - newSize.Width / 2,
                                componentRect.Top + componentRect.Height / 30);

            int amountOfGateIn = currentComponent.gateIn.Count();

            int amountOfGateOut = currentComponent.gateOut.Count();


            DrawComponentLine(amountOfGateIn, amountOfGateOut, componentRect, inOutX, graphics, currentComponent);


            if (startExist && endExist)
            {
                graphics.DrawLine(Pens.Black, startDrawLine, endDrawLine);
            }

            if (listOfBitmap.Count < 2)
            {
                listOfBitmap.Add(bitmap);
                pictureBox1.BackgroundImage = bitmap;
            }
            else
            {
                pictureBox1.BackgroundImage = listOfBitmap[listOfPictureBox.IndexOf(pictureBox1)];
            }
        }