private void DeserializeForm(string fn) { string statefn = Path.GetTempFileName(); string voxfn = Path.GetTempFileName(); BreakUpFiles(new[] { statefn, voxfn }, fn); ControlStateS.ReadXml(statefn); foreach (DataRow d in ControlStateS.Tables["TextBoxes"].Rows) { SetTextBoxProperties(Controls.Find(d["ControlNames"].ToString(), true)[0] as TextBox, d["Text"].ToString(), (bool)d["Enabled"], (bool)d["ReadOnly"]); } foreach (DataRow d in ControlStateS.Tables["ComboBoxes"].Rows) { SetComboBoxProperties(Controls.Find(d["ControlNames"].ToString(), true)[0] as ComboBox, (int)d["SelectedIndex"], d["Text"].ToString(), (bool)d["Enabled"]); } foreach (DataRow d in ControlStateS.Tables["CheckBoxes"].Rows) { SetCheckBoxProperties(Controls.Find(d["ControlNames"].ToString(), true)[0] as CheckBox, (bool)d["Checked"], (bool)d["Enabled"]); } foreach (DataRow d in ControlStateS.Tables["RadioButtons"].Rows) { SetRadioButtonProperties(Controls.Find(d["ControlNames"].ToString(), true)[0] as RadioButton, (bool)d["Checked"], (bool)d["Enabled"]); } foreach (DataRow d in ControlStateS.Tables["ColorViews"].Rows) { (Controls.Find(d["ControlNames"].ToString(), true)[0] as Panel).BackColor = (Color)d["BackColor"]; } List <Voxel> VoxelsFromFile = new List <Voxel>(); VoxelsS.ReadXml(voxfn); foreach (DataRow d in VoxelsS.Tables["VoxelData"].Rows) { VoxelsFromFile.Add(new Voxel((double)d["W"], (Switch)d["Val"], ((Point)d["Pos"]).X, ((Point)d["Pos"]).Y)); } if (VoxelsFromFile.Count > 0) { Voxel final = VoxelsFromFile.Last(); if (Cur == null) { Cur = new Voxel[final.Position.X + 1, final.Position.Y + 1]; } foreach (Voxel v in VoxelsFromFile) { Cur[v.Position.X, v.Position.Y] = v; } } }
private void SerializeForm(string fn) { foreach (Panel l in this.Descendants <Panel>()) { ControlStateS.Tables["ColorViews"].Rows.Add(l.Name, l.BackColor); } ControlStateS.Tables["ColorViews"].AcceptChanges(); foreach (ComboBox cb in this.Descendants <ComboBox>()) { ControlStateS.Tables["ComboBoxes"].Rows.Add(cb.Name, cb.SelectedIndex, cb.Text, cb.Enabled); } ControlStateS.Tables["ComboBoxes"].AcceptChanges(); foreach (CheckBox chb in this.Descendants <CheckBox>()) { ControlStateS.Tables["CheckBoxes"].Rows.Add(chb.Name, chb.Checked, chb.Enabled); } ControlStateS.Tables["CheckBoxes"].AcceptChanges(); foreach (RadioButton rb in this.Descendants <RadioButton>()) { ControlStateS.Tables["RadioButtons"].Rows.Add(rb.Name, rb.Checked, rb.Enabled); } ControlStateS.Tables["RadioButtons"].AcceptChanges(); foreach (TextBox tb in this.Descendants <TextBox>()) { ControlStateS.Tables["TextBoxes"].Rows.Add(tb.Name, tb.Text, tb.ReadOnly, tb.Enabled); } ControlStateS.Tables["TextBoxes"].AcceptChanges(); Console.Write("Finished saving control states, proceeding to voxel data (if present).\r\n"); if (Cur != default(Voxel[, ])) { foreach (Voxel v in Cur) { VoxelsS.Tables["VoxelData"].Rows.Add((int)v.Value, v.Weight, v.Position); Console.Write("hc" + v.GetHashCode() + " written\r\n"); } } string statefn = Path.GetTempFileName(); string voxfn = Path.GetTempFileName(); ControlStateS.WriteXml(statefn); VoxelsS.WriteXml(voxfn); if (File.Exists(fn)) { File.Delete(fn); } CombineFiles(new[] { statefn, voxfn }, fn); }