Guest User

Untitled

a guest
May 21st, 2018
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.20 KB | None | 0 0
  1.  {
  2.         try
  3.             {
  4.                 using (XmlReader reader = XmlReader.Create("U:/Visual Studio 2010/Projects/CrazyColourThing/CrazyColourThing/bin/Debug/Shapes.xml"))
  5.                 {
  6.                    
  7.                     while (reader.Read())
  8.                     {
  9.                         if (reader.IsStartElement())
  10.                         {
  11.                             reader.ReadToFollowing("Shape");
  12.  
  13.                             string shapetype = reader.ReadElementContentAsString();
  14.  
  15.                             if (shapetype == "Circle")
  16.                             {
  17.  
  18.                                 int x = Convert.ToInt32(reader.ReadElementContentAsString());                            
  19.                                 int y = Convert.ToInt32(reader.ReadElementContentAsString());
  20.                                 string fill = reader.ReadElementContentAsString();
  21.  
  22.                                 Ellipse newEllipse1 = new Ellipse();
  23.                                 newEllipse1.Width = 30;
  24.                                 newEllipse1.Height = 30;
  25.  
  26.                                 BrushConverter conv = new BrushConverter();
  27.                                 newEllipse1.Fill = conv.ConvertFromString(fill) as SolidColorBrush;
  28.  
  29.                                 Canvas.SetLeft(newEllipse1, x);
  30.                                 Canvas.SetTop(newEllipse1, y);
  31.  
  32.                                 myCanvasmain.Children.Add(newEllipse1);
  33.  
  34.                                                                            
  35.                             }
  36.                             if (shapetype == "Square")
  37.                             {
  38.                                
  39.                                 int x = Convert.ToInt32(reader.ReadElementContentAsString());
  40.                                 int y = Convert.ToInt32(reader.ReadElementContentAsString());                                
  41.                                 string fill = reader.ReadElementContentAsString();
  42.  
  43.                                 Rectangle newRectangle1 = new Rectangle();
  44.                                 newRectangle1.Width = 30;
  45.                                 newRectangle1.Height = 30;
  46.  
  47.                                 BrushConverter conv = new BrushConverter();
  48.                                 newRectangle1.Fill = conv.ConvertFromString(fill) as SolidColorBrush;
  49.  
  50.                                 Canvas.SetLeft(newRectangle1, x);
  51.                                 Canvas.SetTop(newRectangle1, y);
  52.  
  53.                                 myCanvasmain.Children.Add(newRectangle1);
  54.  
  55.                             }                        
  56.                            
  57.                             if (shapetype == "Triangle")
  58.                             {
  59.                                
  60.                                 int x = Convert.ToInt32(reader.ReadElementContentAsString());
  61.                                 int y = Convert.ToInt32(reader.ReadElementContentAsString());
  62.                                 string fill = reader.ReadElementContentAsString();
  63.  
  64.                                 Polygon newTriangle1 = new Polygon();
  65.                                 PointCollection myPointCollection = new PointCollection();
  66.                                 myPointCollection.Add(new Point(0, 15));
  67.                                 myPointCollection.Add(new Point(15, -15));
  68.                                 myPointCollection.Add(new Point(30, 15));
  69.                                 newTriangle1.Points = myPointCollection;
  70.                                 newTriangle1.Width = 100;
  71.                                 newTriangle1.Height = 100;
  72.                                 newTriangle1.StrokeThickness = 2;
  73.  
  74.                                 BrushConverter conv = new BrushConverter();
  75.                                 newTriangle1.Fill = conv.ConvertFromString(fill) as SolidColorBrush;
  76.  
  77.                                 Canvas.SetLeft(newTriangle1, x);
  78.                                 Canvas.SetTop(newTriangle1, y);
  79.  
  80.                                 myCanvasmain.Children.Add(newTriangle1);
  81.  
  82.                             }
  83.                        }                      
  84.                    }
  85.                    
  86.                     reader.Close();
Add Comment
Please, Sign In to add comment