private void btn_save_Click(object sender, EventArgs e) { //将设置后的用户信息序列化到文件中 UserInfo user = new UserInfo(); user.NickName = this.tb_nickname.Text; user.shuoshuo = this.rtb_shuoshuo.Text; user.HeadImageIndex = this.listImages.SelectedIndex; this.Userinfo = user; IFormatter formater = new BinaryFormatter(); Stream stream = new FileStream("UserInfo.bin", FileMode.Create, FileAccess.Write, FileShare.ReadWrite); formater.Serialize(stream,user); stream.Close(); //主窗体同步设置后的信息 object[] pars = new object[1]; pars[0] = user; frm.Invoke(new delSyncUserInfo(frm.SyncUserInfo), pars); this.Close(); }
public void SyncUserInfo(UserInfo user) { this.userNick.Text = user.NickName; this.userHeadImage.Image = this.ilHeadImages.Images[user.HeadImageIndex]; this.userShuoshuo.Text = user.shuoshuo; }
private void mainform_Load(object sender, EventArgs e) { IPAddress myIP = Operate.getMyIP(); if(myIP==null) { MessageBox.Show("未找到可用网卡,请检查!"); Application.Exit(); } mainform.CheckForIllegalCrossThreadCalls = false; Operate ope = new Operate(this); t = new Thread(new ThreadStart(ope.listen)); Thread.Sleep(100); t.IsBackground = true; t.Start(); try { //将存储用户信息的文件反序列化出来 IFormatter formater = new BinaryFormatter(); Stream stream = new FileStream("UserInfo.bin", FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite); user = (UserInfo)formater.Deserialize(stream); stream.Close(); this.userNick.Text = user.NickName; this.userHeadImage.Image = this.ilHeadImages.Images[user.HeadImageIndex]; this.userShuoshuo.Text = user.shuoshuo; } catch { MessageBox.Show("您首次使用此软件,赶快去设置自己的资料让小伙伴识别你吧!"); } string msg = "LOGIN|" + this.userNick.Text +"|19|" + this.userShuoshuo.Text; ipep = new IPEndPoint(IPAddress.Parse("255.255.255.255"), 9527); SendMessage(msg, ipep); }