private void bt_view_list_Click(object sender, EventArgs e) { //reset flpn_post flpn_post.Controls.Clear(); foreach (Post p in post_Q) { //alloc new post panel and set data UserControl1 tmp = new UserControl1(); tmp.SetProfile(pb_profile.Image); tmp.SetId(login_id); tmp.SetTime(new DateTimeConverter().ConvertToString(p.time)); tmp.SetPic(new ImageConverter().ConvertFrom(p.picture) as Image); tmp.SetComment(p.comment); //add flpn_post flpn_post.Controls.Add(tmp); } }
private void load_home() { //reset post_Q & map& flpn_home this.post_Q.Clear(); this.map.Clear(); flpn_home.Controls.Clear(); //set request packet to server this.post = new Post(); this.post.Type = (int)PacketType.post; this.post.purpose = 2; //send request packet to server Packet.Serialize(this.post).CopyTo(w_buffer, 0); this.send(); Thread.Sleep(5000); //receive packet until end while (this.stream.DataAvailable) { //receive result packet from server //if error occur during prepare stream & r_buffer if (!preparing_receive()) { return; } Packet packet = (Packet)Packet.Deserialize(this.r_buffer); switch (packet.Type) { //if receive Member packet case (int)PacketType.member: { this.member = (Member)Packet.Deserialize(this.r_buffer); if (this.member.purpose == 5) { try { map.Add(this.member.ID, new ImageConverter().ConvertFrom(this.member.profile_pic) as Image); } catch (ArgumentException e) { MessageBox.Show(string.Format("duplicate id when input data map... id : {0}", this.member.ID)); } } } break; //if receive Post packet case (int)PacketType.post: { this.post = (Post)Packet.Deserialize(this.r_buffer); if (this.post.purpose == 2) { this.post_Q.Enqueue(this.post); } } break; } } //add post at flpn_home foreach (Post p in post_Q) { //alloc new post panel and set data UserControl1 tmp = new UserControl1(); tmp.SetProfile(map[p.ID]); tmp.SetId(p.ID); tmp.SetPic(new ImageConverter().ConvertFrom(p.picture) as Image); tmp.SetComment(p.comment); tmp.SetTime(new DateTimeConverter().ConvertToString(p.time)); //add flpn_post flpn_home.Controls.Add(tmp); } }