public void save(string path) { //convert to savable format since i can't save windows form objects savable temp = new savable(); foreach (Component c in elements) { element_object elem = new element_object(); elem.name = c.name; elem.voltage = c.voltage; elem.current = c.current; elem.resistance = c.resistance; elem.numconnections = c.numconnections; elem.type = c.type; elem.box_name = c.box.Name; elem.colour = c.box.BackColor; elem.width = c.box.ClientSize.Width; elem.hight = c.box.ClientSize.Height; elem.location = c.box.Location; temp.elements.Add(elem); } foreach (Tuple <string, string> t in connections) { temp.connections.Add(t); } temp.element_counter = element_counter; //save to json using (StreamWriter file = File.CreateText(path)) { JsonSerializer serializer = new JsonSerializer(); serializer.Serialize(file, temp); } }
//general button handler public void general_button_handler(object sender, EventArgs e) { Button temp = (sender as Button); state = ""; updatebuttons(); //find the button data element_object data = buttons.Find(i => i.name == temp.Name); // make the component makebox(data.colour, data.name, data.width, data.hight, data.voltage, data.current, data.resistance, data.numconnections); }