// Client Name Changed private void ClientNameChanged(string clientName, string newClientName) { // Change the ListViewItem.name in ListViewClients Invoke(new Action(delegate { foreach (ClientMessagesPosition clientMessagesPosition in _ClientMessagesesList) { if (clientMessagesPosition.ClientName == clientName) { clientMessagesPosition.ClientName = newClientName; } } for (int i = 0; i < ListViewClients.Items.Count; i++) { if (ListViewClients.Items[i].Name != clientName) { continue; } ListViewClients.Items[i].Text = newClientName; ListViewClients.Items[i].Name = newClientName; break; } foreach (TabPagePrivateChatServer tabPage in TabControlServer.TabPages.OfType <TabPagePrivateChatServer>()) { if (tabPage.ClientName == clientName) { tabPage.ClientName = newClientName; tabPage.Text = newClientName + @" - " + tabPage.ClientNamePrivate; TabControlServer.Invalidate(); } if (tabPage.ClientNamePrivate == clientName) { tabPage.ClientNamePrivate = newClientName; tabPage.Text = tabPage.ClientName + @" - " + newClientName; TabControlServer.Invalidate(); } } TabFormat.ItemEvenSize(TabControlServer); // The inner server messages board RichTextServerConn.SelectionStart = _CursorPositionConn; RichTextServerConn.SelectionColor = Color.Black; RichTextServerConn.SelectionBackColor = Color.CornflowerBlue; RichTextServerConn.SelectedText += @"<<< " + clientName + @" have changed his name to " + newClientName + " " + Time.NowTimeDate() + @" >>>" + Environment.NewLine; _CursorPositionConn = RichTextServerConn.SelectionStart; })); if (FrmServerImagesChangeNameEvent != null) { FrmServerImagesChangeNameEvent.Invoke(clientName, newClientName); } }
// Private start private void PrivateStart(string clientNamePrivate) { if (TabControlClient.TabPages.Cast <TabPage>().Any(tabPagePrivateChat => tabPagePrivateChat.Name == clientNamePrivate)) { if (TabPagePrivateChatReceiveClientEvent != null) { TabPagePrivateChatReceiveClientEvent.Invoke(clientNamePrivate, null, null, TabPagePrivateChatClient.TabCommand.Resumed); } return; } Invoke(new Action((delegate { NewTabPagePrivateChatClient(clientNamePrivate); TabFormat.ItemEvenSize(TabControlClient); }))); }
// List box Clients double click private void ListBoxClientList_DoubleClick(object sender, EventArgs e) { if (ListBoxClientList.SelectedItem.ToString() == Client.Name) { MessageBox.Show(@"You can't start a private chat with yourself", @"Chat: " + Client.Name, MessageBoxButtons.OK, MessageBoxIcon.Information); return; } if (TabControlClient.TabPages.OfType <TabPagePrivateChatClient>().Any(tabPagePrivateChat => tabPagePrivateChat.Name == ListBoxClientList.SelectedItem.ToString())) { MessageBox.Show(@"That private chat already opned", @"Chat: " + Client.Name, MessageBoxButtons.OK, MessageBoxIcon.Information); return; } ClientNetworkEngine.StartPrivateChat(ListBoxClientList.SelectedItem.ToString()); NewTabPagePrivateChatClient(ListBoxClientList.SelectedItem.ToString()); TabFormat.ItemEvenSize(TabControlClient); }
// Private Chat Started private void PrivateChatStarted(string clientName, string clientNamePrivate) { if (TabControlServer.TabPages.OfType <TabPagePrivateChatServer>().Any(tabPagePrivateChatServer => tabPagePrivateChatServer.ClientName == clientName && tabPagePrivateChatServer.ClientNamePrivate == clientNamePrivate || tabPagePrivateChatServer.ClientName == clientNamePrivate && tabPagePrivateChatServer.ClientNamePrivate == clientName)) { if (TabPagePrivateServerDoActionEvent != null) { TabPagePrivateServerDoActionEvent.Invoke(clientName, clientNamePrivate, null, TabPagePrivateChatServer.TabCommand.Resumed); } return; } Invoke(new Action(delegate { NewTabPagePrivateChatServer(clientName, clientNamePrivate); TabFormat.ItemEvenSize(TabControlServer); })); //Invoke(new Action(delegate{ //})); }
// Name change private void NameChange(string clientName, string clientNameNew, Color color) { Invoke(new Action((delegate { int index = ListBoxClientList.FindString(clientName); ListBoxClientList.Items[index] = clientNameNew; foreach (ClientChatHistory clientColor in _ClientChatHistoryList.Where(ClientChatHistory => ClientChatHistory.Name == clientName)) { clientColor.Name = clientNameNew; } RichTextClientPub.SelectionStart = _CursorPosition; RichTextClientPub.SelectionColor = Color.Black; RichTextClientPub.SelectionBackColor = Color.CornflowerBlue; RichTextClientPub.SelectedText = Time.NowTime() + " " + @"<<< " + clientName + @" have changed nickname to " + clientNameNew + @" >>>" + Environment.NewLine; _CursorPosition = RichTextClientPub.SelectionStart; if (Client.Name == clientNameNew) { Text = @"Chat: " + clientNameNew; } if (TabPagePrivateChatReceiveClientEvent != null) { TabPagePrivateChatReceiveClientEvent.Invoke(clientName, null, clientNameNew, TabPagePrivateChatClient.TabCommand.NameChange); } foreach (TabPage tabPage in TabControlClient.TabPages.Cast <TabPage>().Where(tabPage => tabPage.Name == clientName)) { tabPage.Name = clientNameNew; tabPage.Text = clientNameNew; TabControlClient.Invalidate(); } TabFormat.ItemEvenSize(TabControlClient); }))); Invoke(new Action((delegate { _FrmClientImages.Text = clientNameNew + @" Received Images"; }))); if (FrmClientImagesChangeNameEvent != null) { FrmClientImagesChangeNameEvent.Invoke(clientName, clientNameNew); } ColorChanged(clientName, color); }
// Client to add private void ClientToAdd(string clientNameToAdd, IPEndPoint clientNameToAddIpEndPoint) { ClientMessagesPosition newClientMessagesPosition = new ClientMessagesPosition(clientNameToAdd); _ClientMessagesesList.Add(newClientMessagesPosition); Invoke(new Action((delegate { ListViewItem newRow = new ListViewItem(new[] { clientNameToAdd, clientNameToAddIpEndPoint.ToString(), Time.NowTimeDate() }) { Name = clientNameToAdd }; ListViewClients.Items.Add(newRow); // The inner server messages board RichTextServerConn.SelectionStart = _CursorPositionConn; RichTextServerConn.SelectionBackColor = Color.LightGreen; RichTextServerConn.SelectionColor = Color.Black; RichTextServerConn.SelectedText += " <<< " + clientNameToAdd + " has joined the room >>>" + Environment.NewLine; TabFormat.ItemEvenSize(TabControlServer); _CursorPositionConn = RichTextServerConn.SelectionStart; }))); }