Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- {
- try
- {
- using (XmlReader reader = XmlReader.Create("U:/Visual Studio 2010/Projects/CrazyColourThing/CrazyColourThing/bin/Debug/Shapes.xml"))
- {
- while (reader.Read())
- {
- if (reader.IsStartElement())
- {
- reader.ReadToFollowing("Shape");
- string shapetype = reader.ReadElementContentAsString();
- if (shapetype == "Circle")
- {
- int x = Convert.ToInt32(reader.ReadElementContentAsString());
- int y = Convert.ToInt32(reader.ReadElementContentAsString());
- string fill = reader.ReadElementContentAsString();
- Ellipse newEllipse1 = new Ellipse();
- newEllipse1.Width = 30;
- newEllipse1.Height = 30;
- BrushConverter conv = new BrushConverter();
- newEllipse1.Fill = conv.ConvertFromString(fill) as SolidColorBrush;
- Canvas.SetLeft(newEllipse1, x);
- Canvas.SetTop(newEllipse1, y);
- myCanvasmain.Children.Add(newEllipse1);
- }
- if (shapetype == "Square")
- {
- int x = Convert.ToInt32(reader.ReadElementContentAsString());
- int y = Convert.ToInt32(reader.ReadElementContentAsString());
- string fill = reader.ReadElementContentAsString();
- Rectangle newRectangle1 = new Rectangle();
- newRectangle1.Width = 30;
- newRectangle1.Height = 30;
- BrushConverter conv = new BrushConverter();
- newRectangle1.Fill = conv.ConvertFromString(fill) as SolidColorBrush;
- Canvas.SetLeft(newRectangle1, x);
- Canvas.SetTop(newRectangle1, y);
- myCanvasmain.Children.Add(newRectangle1);
- }
- if (shapetype == "Triangle")
- {
- int x = Convert.ToInt32(reader.ReadElementContentAsString());
- int y = Convert.ToInt32(reader.ReadElementContentAsString());
- string fill = reader.ReadElementContentAsString();
- Polygon newTriangle1 = new Polygon();
- PointCollection myPointCollection = new PointCollection();
- myPointCollection.Add(new Point(0, 15));
- myPointCollection.Add(new Point(15, -15));
- myPointCollection.Add(new Point(30, 15));
- newTriangle1.Points = myPointCollection;
- newTriangle1.Width = 100;
- newTriangle1.Height = 100;
- newTriangle1.StrokeThickness = 2;
- BrushConverter conv = new BrushConverter();
- newTriangle1.Fill = conv.ConvertFromString(fill) as SolidColorBrush;
- Canvas.SetLeft(newTriangle1, x);
- Canvas.SetTop(newTriangle1, y);
- myCanvasmain.Children.Add(newTriangle1);
- }
- }
- }
- reader.Close();
Add Comment
Please, Sign In to add comment