using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Xml; namespace interaktivni { public partial class Form1 : Form { public static string NetFile { get; set; } public static string InputFile { get; set; } public Form1() { InitializeComponent(); } private void pictureBox1_Paint(object sender, PaintEventArgs e) { try { var xml = new XmlDocument(); xml.Load(NetFile); var g = e.Graphics; g.Clear(Color.White); foreach (XmlElement item in xml.ChildNodes[0].ChildNodes) { switch (item.Name) { case "input": DrawInput(g, item); break; case "output": DrawOutput(g, item); break; case "gate": DrawGate(g, item); break; default: throw new NotSupportedException("Tag " + item.Name + " neni podporovany."); } } } catch (Exception exception) { MessageBox.Show("Program skoncil chybou: " + exception.Message); Application.Exit(); } } private void DrawInput(Graphics g, XmlElement item) { var rect = GetRectangle(item); g.DrawRectangle(Pens.Red, rect); } private void DrawOutput(Graphics g, XmlElement item) { var rect = GetRectangle(item); g.DrawRectangle(Pens.Green, rect); } private void DrawGate(Graphics g, XmlElement item) { var rect = GetRectangle(item); g.DrawRectangle(Pens.Black, rect); /*foreach (XmlElement child in item.ChildNodes) { switch (child.Name) { case "input": DrawInput(g, item); break; case "output": DrawOutput(g, item); break; default: throw new NotSupportedException("Tag " + item.Name + " neni podporovany."); } }*/ } private Rectangle GetRectangle(XmlElement item) { int x = int.Parse(item.Attributes["x"].Value); int y = int.Parse(item.Attributes["y"].Value); int w = int.Parse(item.Attributes["w"].Value); int h = int.Parse(item.Attributes["h"].Value); return new Rectangle(x, y, w, h); } } }