private void OpenFileXml(bool runIt, string file) { //Get data from XML file XmlSerializer ser = new XmlSerializer(typeof(ActionsEntry)); using (FileStream fs = System.IO.File.Open(file, FileMode.Open)) { try { ActionsEntry entry = (ActionsEntry)ser.Deserialize(fs); lvActions.Items.Clear(); foreach (ActionsEntryAction ae in entry.Action) { string point = ae.X.ToString() + "," + ae.Y.ToString(); string interval = (ae.interval).ToString(); ListViewItem lvi = new ListViewItem(new string[] { point, ((ClickType)(ae.Type)).ToString(), interval, ae.Text }); ActionEntry acion = new ActionEntry(ae.X, ae.Y, ae.Text, ae.interval, (ClickType)(ae.Type)); lvi.Tag = acion; lvActions.Items.Add(lvi); } if (runIt) { btnStart.PerformClick(); } } catch (Exception ex) { MessageBox.Show(ex.Message, "Clicer", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
private void btnSave_Click(object sender, EventArgs e) { SaveFileDialog file = new SaveFileDialog(); file.Filter = "XML File |*.xml"; if (file.ShowDialog() == DialogResult.OK) { XmlSerializer ser = new XmlSerializer(typeof(ActionsEntry)); ActionsEntry tmpAction = new ActionsEntry(); List <ActionsEntryAction> tmpActionsEntryActions = new List <ActionsEntryAction>(); foreach (ListViewItem lvi in lvActions.Items) { ActionEntry tmpActionEntry = lvi.Tag as ActionEntry; ActionsEntryAction tmpActionsEntryAction = new ActionsEntryAction(); tmpActionsEntryAction.X = tmpActionEntry.X; tmpActionsEntryAction.Y = tmpActionEntry.Y; tmpActionsEntryAction.Text = tmpActionEntry.Text; tmpActionsEntryAction.interval = tmpActionEntry.Interval; tmpActionsEntryAction.Type = (int)tmpActionEntry.Type; tmpActionsEntryActions.Add(tmpActionsEntryAction); } tmpAction.Action = tmpActionsEntryActions.ToArray(); using (XmlWriter writer = XmlWriter.Create(file.FileName)) { ser.Serialize(writer, tmpAction); } } }
private void btnSave_Click(object sender, EventArgs e) { SaveFileDialog file = new SaveFileDialog(); file.Filter = "XML File |*.xml"; if (file.ShowDialog() == DialogResult.OK) { XmlSerializer ser = new XmlSerializer(typeof(ActionsEntry)); ActionsEntry tmpAction = new ActionsEntry(); List<ActionsEntryAction> tmpActionsEntryActions = new List<ActionsEntryAction>(); foreach (ListViewItem lvi in lvActions.Items) { ActionEntry tmpActionEntry = lvi.Tag as ActionEntry; ActionsEntryAction tmpActionsEntryAction = new ActionsEntryAction(); tmpActionsEntryAction.X = tmpActionEntry.X; tmpActionsEntryAction.Y = tmpActionEntry.Y; tmpActionsEntryAction.Text = tmpActionEntry.Text; tmpActionsEntryAction.interval = tmpActionEntry.Interval; tmpActionsEntryAction.Type = (int)tmpActionEntry.Type; tmpActionsEntryActions.Add(tmpActionsEntryAction); } tmpAction.Action = tmpActionsEntryActions.ToArray(); using (XmlWriter writer = XmlWriter.Create(file.FileName)) { ser.Serialize(writer, tmpAction); } } }