private void UpdateDisplayPanel(Entities.TextMessage msg) { if (msg.Type == TextMessageType.TextMessage) { txtRecieved.Text = msg.Msg; ChatBallon ballon = new ChatBallon() { ChatText = msg.Msg, ChatBallonDirection = Direction.LeftToRight }; ChatBallon cb = null; try { cb = (ChatBallon)panel1.Controls[panel1.Controls.Count - 1]; ballon.Location = new Point(0, cb.Location.Y + cb.Height); panel1.Controls.Add(ballon); } catch { panel1.Controls.Add(ballon); } } else if (msg.Type == TextMessageType.StatusMessage) { if (usersList.Count(x => x.IPAddress == msg.User.IPAddress) == 0) { usersList.Add(msg.User); StatusIndicator si = new StatusIndicator(msg.User.DisplayName, msg.User.Status, msg.User.IPAddress); flowLayoutPanel1.Controls.Add(si); } listBox1.DataSource = usersList.Select(u => u.DisplayName).ToList <string>(); } }
public frmChatWindow(StatusIndicator si) { InitializeComponent(); SI = si; Me = new Entities.User(); com = new UDPComm(); com.TextMessageRecieved += Com_MessageRecieved; com.Start(); }
private void Si_Click(object sender, EventArgs e) { StatusIndicator si = (StatusIndicator)sender; frmChatWindow frm = new frmChatWindow(si); frm.FormClosing += Frm_FormClosing; Me = new User(Entities.Properties.Settings.Default.DisplayName, (UserStatus)Entities.Properties.Settings.Default.Status, com.GetMyIPAddress()); frm.ClientIPAddress = si.IpAddress; frm.Me = Me; if (chatWindows.Count(x => x.SI.IpAddress == si.IpAddress) == 0) { chatWindows.Add(frm); } frm.Show(); frm.Location = new Point(Screen.PrimaryScreen.WorkingArea.Width - (Width + frm.Width), Screen.PrimaryScreen.WorkingArea.Height - frm.Height); }
private void UpdateDisplayPanel(Entities.Message msg) { if (msg.Type == MessageType.TextMessage) { if (msg.User.IPAddress != Me.IPAddress) { try { frmChatWindow frm = chatWindows.Where(f => f.SI.IpAddress == msg.User.IPAddress).FirstOrDefault(); if (frm == null) { frm = new frmChatWindow(new StatusIndicator(msg.User.DisplayName, msg.User.Status, msg.User.IPAddress)); frm.FormClosing += Frm_FormClosing; Me = new User(Entities.Properties.Settings.Default.DisplayName, (UserStatus)Entities.Properties.Settings.Default.Status, com.GetMyIPAddress()); frm.ClientIPAddress = msg.User.IPAddress; frm.Me = Me; if (chatWindows.Count(x => x.SI.IpAddress == msg.User.IPAddress) == 0) { chatWindows.Add(frm); } //frm.DisplayChat(msg); if (Me.Status == UserStatus.Available) { frm.Show(); } else //This is for testing purpose { foreach (StatusIndicator s in flContainer.Controls) { if (msg.User.IPAddress == s.IpAddress) { s.NumberOfUnreadMessages++; break; } } } frm.Location = new Point(Screen.PrimaryScreen.WorkingArea.Width - (Width + frm.Width), Screen.PrimaryScreen.WorkingArea.Height - frm.Height); } else //This is for testing purpose { foreach (StatusIndicator s in flContainer.Controls) { if (msg.User.IPAddress == s.IpAddress) { s.NumberOfUnreadMessages++; break; } } } frm.DisplayChat(msg); } catch { } } } else if (msg.Type == MessageType.StatusMessage) { if (usersList.Count(x => x.IPAddress == msg.User.IPAddress) == 0) { usersList.Add(msg.User); StatusIndicator si = new StatusIndicator(msg.User.DisplayName, msg.User.Status, msg.User.IPAddress); si.Click += Si_Click; si.Width = flContainer.Width - 2; flContainer.Controls.Add(si); } else { int index = usersList.IndexOf(usersList.Where(x => x.IPAddress == msg.User.IPAddress).First()); ((StatusIndicator)flContainer.Controls[index]).Status = msg.User.Status; ((StatusIndicator)flContainer.Controls[index]).DisplayName = msg.User.DisplayName; } } }