public void update_msg_panel() // 채팅창 닫힐 때 패널 업데이트 { Msg_list msg = new Msg_list(); msg.Type = (int)PacketType.메시지개수; msg.recv_name = ID_txtBox.Text; Packet.Serialize(msg).CopyTo(this.sendBuffer, 0); this.Send(); this.Recv(); Packet packet = (Packet)Packet.Deserialize(this.readBuffer); if (packet.Type == (int)PacketType.메시지개수) { msg = (Msg_list)Packet.Deserialize(this.readBuffer); if (msg.count == 0) { msg_count.Visible = false; } else { msg_count.Text = msg.count.ToString(); msg_count.Visible = true; } } }
private void recv_inform(object sender, EventArgs e) { for (int i = 0; i < client_list.Count; i++) { PictureBox box = sender as PictureBox; if (box == pic[i]) { if (la[i].ForeColor == Color.Black) // 수신 확인 표시 { la[i].ForeColor = Color.Gray; Msg_list msg = new Msg_list(); msg.Type = (int)PacketType.수신확인; msg.recv_name = curID; msg.send_name = la[i].Text; msg.date = date_list[i].ToString(); msg.text = msg_list[i].ToString(); Packet.Serialize(msg).CopyTo(this.sendBuffer, 0); this.Send(); form.update_msg_panel(); } sendMsg mChild = new sendMsg(form, la[i].Text, date_list[i].ToString(), msg_list[i].ToString(), 0); mChild.ShowDialog(); break; } } }
private void pictureBox1_Click(object sender, EventArgs e) { Msg_list send = new Msg_list(); send.Type = (int)PacketType.메시지송신; send.date = DateTime.Now.ToString(); send.send_name = curID; send.recv_name = recvID; send.text = textBox2.Text; Packet.Serialize(send).CopyTo(this.sendBuffer, 0); this.Send(); MessageBox.Show("Message sent Complete !"); this.Close(); }
private void msg_list_inform(int num) // 메시지 송수신 리스트 관리 { int type; Panel pan; if (num == 1) // 송신 리스트 { type = (int)PacketType.송신리스트; pan = panel4; } else // 수신 리스트 { type = (int)PacketType.수신리스트; pan = panel6; } pan.Controls.Clear(); Msg_list send = new Msg_list(); send.Type = type; send.recv_name = curID; Packet.Serialize(send).CopyTo(this.sendBuffer, 0); this.Send(); // 계정 리스트 수신 Packet packet = this.Recv(); if (packet.Type == type) // 송수신 리스트 받아오기 { while (true) { send = (Msg_list)Packet.Deserialize(this.readBuffer); if (send.count == -1) { break; } // MessageBox.Show(send.send_name); client_list.Add(send.send_name); msg_list.Add(send.text); date_list.Add(send.date); used_list.Add(send.used); packet = this.Recv(); } int k = 0; // 계정의 개수 만큼 picturbox 및 label 생성 pic = new PictureBox[client_list.Count]; la = new Label[client_list.Count]; for (int x = client_list.Count - 1; x >= 0; x--) // 패널에 계정 리스트 label 및 picturbox 추가 { string sendID = client_list[x].ToString(); pic[x] = new PictureBox(); pic[x].Image = Image.FromFile("detail.png"); pic[x].SizeMode = PictureBoxSizeMode.StretchImage; pic[x].Location = new Point(215, 20 + k); pic[x].Size = new Size(25, 25); pan.Controls.Add(pic[x]); if (num == 1) { pic[x].Click += new EventHandler(send_inform); } else { pic[x].Click += new EventHandler(recv_inform); } DateTime date = Convert.ToDateTime(date_list[x]); la[x] = new Label(); if (int.Parse(used_list[x].ToString()) == 0 || num == 1) { la[x].ForeColor = Color.Black; } else { la[x].ForeColor = Color.Gray; } la[x].Text = sendID; la[x].AutoSize = false; la[x].Font = new Font("Arial", 10); la[x].Location = new Point(20, 20 + k); la[x].Size = new Size(210, 20); pan.Controls.Add(la[x]); k += 30; } } }