Advertisement
Guest User

Untitled

a guest
Oct 16th, 2019
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.63 KB | None | 0 0
  1. if (openFileDialog1.ShowDialog() == DialogResult.Cancel)
  2.                 return;
  3.            
  4.             string filename = openFileDialog1.FileName;
  5.             StreamReader R = new StreamReader(filename);
  6.             myGraph = new Graph(R);
  7.             input_nVertex = myGraph.nVerts;
  8.  
  9.             pictureBox1.Image = (Image)new Bitmap(pictureBox1.Width, pictureBox1.Height);
  10.             Graphics g = Graphics.FromImage(pictureBox1.Image);
  11.             Pen p = new Pen(Color.Black, 3);
  12.  
  13.  
  14.             //float heightSeparation = pictureBox1.Height / myGraph.nVerts;
  15.             //float widthSeparation = pictureBox1.Width / myGraph.nVerts;
  16.  
  17.             float circleSeparation = Convert.ToSingle(2 * Math.PI) / myGraph.nVerts;
  18.  
  19.             float centerX = pictureBox1.Width / 2;
  20.             float centerY = pictureBox1.Height / 2;
  21.             //g.TranslateTransform(centerX, centerY);
  22.  
  23.             for (int i = 1; i <= myGraph.nVerts; i++)
  24.             {
  25.                 //PointF startPoint = new PointF(i * widthSeparation, i * heightSeparation);
  26.                 //PointF endPoint = new PointF(startPoint.X - 15, startPoint.Y - 15);
  27.                 //PointF centerPoint = new PointF(Convert.ToSingle(15 * Math.Cos((2 * Math.PI) / myGraph.nVerts) * i), Convert.ToSingle(15 * Math.Sin((2 * Math.PI) / myGraph.nVerts) * i));
  28.                 PointF centerPoint = new PointF(170 * Convert.ToSingle(Math.Cos(circleSeparation * i)) + centerX, 170 * Convert.ToSingle(Math.Sin   (circleSeparation * i)) + centerY);
  29.                 g.FillEllipse(Brushes.White, centerPoint.X - 25, centerPoint.Y - 25, 50, 50);
  30.                 g.DrawEllipse(p, centerPoint.X - 25, centerPoint.Y - 25, 50, 50);
  31.  
  32.                 Point stringPoint = new Point(Convert.ToInt32(centerPoint.X - 13), Convert.ToInt32(centerPoint.Y - 13));
  33.                 g.DrawString(myGraph.vertexList[i - 1].label, new Font("Arial", 20), Brushes.Black, stringPoint);
  34.  
  35.                 myGraph.vertexList[i - 1].centerPoint = centerPoint;
  36.             }
  37.             for (int i = 0; i < myGraph.nVerts; i++)
  38.             {
  39.                 for (int j = 0; j < myGraph.nVerts; j++)
  40.                 {
  41.                     if (myGraph.adjMatrix[i][j] != 0)
  42.                     {
  43.                         PointF startPosition = myGraph.vertexList[i].centerPoint;
  44.                         PointF endPosition = myGraph.vertexList[j].centerPoint;
  45.                         g.DrawLine(Pens.Black, startPosition, endPosition);
  46.  
  47.                         g.FillEllipse(Brushes.White, startPosition.X - 25, startPosition.Y - 25, 50, 50);
  48.                         g.DrawEllipse(p, startPosition.X - 25, startPosition.Y - 25, 50, 50);
  49.                         g.FillEllipse(Brushes.White, endPosition.X - 25, endPosition.Y - 25, 50, 50);
  50.                         g.DrawEllipse(p, endPosition.X - 25, endPosition.Y - 25, 50, 50);
  51.  
  52.                         PointF stringPoint = new PointF(Convert.ToInt32(startPosition.X - 13), Convert.ToInt32(startPosition.Y - 13));
  53.                         g.DrawString(myGraph.vertexList[i].label, new Font("Arial", 20), Brushes.Black, stringPoint);
  54.  
  55.                         stringPoint = new PointF(Convert.ToInt32(endPosition.X - 13), Convert.ToInt32(endPosition.Y - 13));
  56.                         g.DrawString(myGraph.vertexList[j].label, new Font("Arial", 20), Brushes.Black, stringPoint);
  57.  
  58.                         stringPoint = new PointF((startPosition.X + endPosition.X) / 2, (startPosition.Y + endPosition.Y) / 2);
  59.                         g.DrawString(myGraph.adjMatrix[i][j].ToString(), new Font("Arial", 20), Brushes.Black, stringPoint);
  60.                     }
  61.                 }
  62.             }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement