private void button1_Click(object sender, EventArgs e) { string s = System.Windows.Forms.Application.StartupPath + "\\AppleLabJ" + @"\record\"; string s1 = this.Width.ToString() + "_" + this.Height.ToString(); openFileDialog1.InitialDirectory = s + s1; openFileDialog1.Filter = "(*.rec" + ")|*.rec"; openFileDialog1.ShowDialog(); myMacroRecord = myMacroRecord.DeSerializeNow(openFileDialog1.FileName); }
public MacroRecord DeSerializeNow(string filename) { MacroRecord c = new MacroRecord(); try { using (FileStream fileStream = new FileStream(filename, FileMode.Open, FileAccess.Read, FileShare.Read)) { BinaryFormatter b = new BinaryFormatter(); c = b.Deserialize(fileStream) as MacroRecord; for (int i = 0; i < c.events.Count; i++) { if ((c.events[i].MacroEventType == MacroEventType.MouseUp) || (c.events[i].MacroEventType == MacroEventType.MouseDown) || (c.events[i].MacroEventType == MacroEventType.MouseMove) || (c.events[i].MacroEventType == MacroEventType.MouseMove)) { c.events[i].EventArgs = new MouseEventArgs((MouseButtons)c.events[i].button, c.events[i].clicks, c.events[i].x, c.events[i].y, c.events[i].delta); } if ((c.events[i].MacroEventType == MacroEventType.KeyUp) || (c.events[i].MacroEventType == MacroEventType.KeyDown)) { c.events[i].EventArgs = new KeyEventArgs(c.events[i].KeyData); } } fileStream.Close(); } } catch (Exception e1) { c = new MacroRecord(); MessageBox.Show(e1.Message, "读取文件"); } finally { } return(c); }