//same shit, another parm private void InitializeComponent(int index, SorterEnvironmentParameters sorterParm) { InitializeComponent(); this.groupBoxFilter.Text = "Filter " + index; this.numericUpDownMin.Maximum = sorterParm.conteinerNumber; this.numericUpDownMin.Minimum = 0; this.numericUpDownMin.Maximum = sorterParm.maxWeight; this.numericUpDownMin.Minimum = sorterParm.minWeight; this.numericUpDownMin.Maximum = sorterParm.maxWeight; this.numericUpDownMin.Minimum = sorterParm.minWeight; for (int i = 0; i < sorterParm.shapes.Count; i++) { this.checkedListBoxShapes.Items.Insert(i, sorterParm.shapes[i]); } for (int i = 0; i < sorterParm.colors.Count; i++) { this.checkedListBoxColor.Items.Insert(i, sorterParm.colors[i]); } }
//load from xml public void LoadParm(out SorterEnvironmentParameters mySEP) { mySEP = this; try { string envParPath = Path.GetFullPath(Path.Combine(Environment.CurrentDirectory, @"..\..\Resource\envParam.xml")); // Create an instance of the XmlSerializer. XmlSerializer serializer = new XmlSerializer(typeof(SorterEnvironmentParameters)); SorterEnvironmentParameters i = new SorterEnvironmentParameters(); using (Stream reader = new FileStream(envParPath, FileMode.Open)) { // Call the Deserialize method to restore the object's state. i = (SorterEnvironmentParameters)serializer.Deserialize(reader); } mySEP = i; } catch (Exception e) { // Let the user know what went wrong. Console.WriteLine("The file could not be read:"); Console.WriteLine(e.Message); } }
//just for generating first xml public void makeXml() { SorterEnvironmentParameters p = new SorterEnvironmentParameters(); p.colors.Add("Blue"); p.colors.Add("Red"); p.maxWeight = 999; p.minWeight = 1; p.shapes.Add("Cube"); p.shapes.Add("Sphere"); p.conteinerNumber = 6; System.Xml.Serialization.XmlSerializer x = new System.Xml.Serialization.XmlSerializer(p.GetType()); x.Serialize(Console.Out, p); Console.WriteLine(); }
public Filter(int index, SorterEnvironmentParameters sorterParm) { InitializeComponent(index + 1, sorterParm); }