public Struct_FormState ReadFile(string path) { FileStream fs = new FileStream(path + "DATA.dat", FileMode.OpenOrCreate); //反序列化对象 BinaryFormatter bformater = new BinaryFormatter(); Struct_FormState state = (Struct_FormState)bformater.Deserialize(fs); fs.Close(); return(state); }
public SZYM(ZMRL parent) { InitializeComponent(); this.parent = parent; Data data = new Data(); this.state = data.ReadFile(path); path = Application.ExecutablePath; exe_name = path.Substring(path.LastIndexOf("\\") + 1); path = path.Substring(0, path.LastIndexOf("\\") + 1); Init(); }
public void WriteFile(string path, Struct_FormState formstate) { FileStream fs = new FileStream(path + "DATA.dat", FileMode.OpenOrCreate); //序列化对象 BinaryFormatter bformater = new BinaryFormatter(); bformater.Serialize(fs, formstate); //转化序列化对象为Byte MemoryStream ms = new MemoryStream(); bformater.Serialize(ms, formstate); byte[] state = ms.GetBuffer(); ////将一个序列化后的byte[]数组还原 //MemoryStream ms = new MemoryStream(byte[] Bytes); //BinaryFormatter bformater = new BinaryFormatter(); //object state = bformater.Serialize(ms); fs.Write(state, 0, state.Length); fs.Close(); }
public ZMRL() { this.DoubleBuffered = true;//设置本窗体 this.SetStyle(ControlStyles.AllPaintingInWmPaint, true); this.SetStyle(ControlStyles.DoubleBuffer, true); this.SetStyle(ControlStyles.UserPaint, true); this.SetStyle(ControlStyles.ResizeRedraw, true); Data data = new Data(); InitializeComponent(); blind(); CreatCalendar(Convert.ToInt32(cbb_year.SelectedValue), Convert.ToInt32(cbb_month.SelectedValue)); boolyear = true; boolmonth = true; InitCalendar(); this.ShowInTaskbar = false; this.StartPosition = FormStartPosition.Manual; //对当前时间的初始化 timer_time.Start(); timer_time.Interval = 1000; #region 窗体初始状态的判断 string path = Application.ExecutablePath; string name = path.Substring(path.LastIndexOf("\\") + 1); path = path.Substring(0, path.LastIndexOf("\\") + 1); if (data.IsExistFile(path)) { state = data.ReadFile(path); if (state.bool_head) { panel_head.Visible = true; } else { panel_head.Visible = false; } if (!state.bool_date) { panel_date.Visible = false; } else if (state.bool_date && state.bool_head) { panel_date.Visible = true; panel_date.Location = new Point(panel_date.Location.X, panel_head.Location.Y); } else if (state.bool_date && !state.bool_head) { panel_date.Visible = true; panel_date.Location = new Point(panel_date.Location.X, panel_main.Location.Y - 16); } if (state.bool_time) { panel_time.Visible = true; } else { panel_time.Visible = false; } if (state.bool_tran) { this.TransparencyKey = this.BackColor; this.FormBorderStyle = FormBorderStyle.None; this.BackgroundImage = null; } else { this.FormBorderStyle = FormBorderStyle.FixedSingle; System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(ZMRL)); this.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("$this.BackgroundImage"))); } this.Location = new Point(state.point_x, state.point_y); } else { state = new Struct_FormState(); state.point_x = 0; state.point_y = 0; state.bool_head = true; state.bool_date = true; state.bool_time = true; state.bool_autorun = false; data.WriteFile(path, state); } #endregion this.panel_main.BackColor = Color.Transparent; this.panel_calendara.BackColor = Color.Transparent; this.panel_date.BackColor = Color.Transparent; this.panel_head.BackColor = Color.Transparent; this.panel_time.BackColor = Color.Transparent; }