// Message private void Message(string clientName, string message, Color color) { Invoke(new Action((delegate { RichTextClientPub.SelectionStart = _CursorPosition; RichTextClientPub.SelectedText = Time.NowTime() + " "; int selectionStart = RichTextClientPub.SelectionStart; RichTextClientPub.SelectionColor = color; RichTextClientPub.SelectedText = clientName + ": " + message; RichTextClientPub.SelectedText = Environment.NewLine; _CursorPosition = RichTextClientPub.SelectionStart; foreach (ClientChatHistory clientChatHistory in _ClientChatHistoryList.Where(clientColor => clientColor.Name == clientName)) { int[] selectionArr = { selectionStart, RichTextClientPub.TextLength - selectionStart }; clientChatHistory.Messages.Add(selectionArr); } }))); if (clientName != Client.Name) { ++ClientStatistics.MessagesReceived; if (FrmStatisticsUpdateEvent != null) { FrmStatisticsUpdateEvent.Invoke(StatisticsEntry.MessageReceied); } } }
// Send private message private void TabPagePrivateChatSendClient(string clientNamePrivate, string message) { ClientNetworkEngine.SendPrivateMessage(clientNamePrivate, message); ++ClientStatistics.MessagesPrivateSent; if (FrmStatisticsUpdateEvent != null) { FrmStatisticsUpdateEvent.Invoke(StatisticsEntry.MessagePrivateSent); } }
// Server message private void ServerMessage(string message) { Invoke(new Action((delegate { RichTextClientPub.SelectionStart = _CursorPosition; RichTextClientPub.SelectionColor = Color.Black; RichTextClientPub.SelectionBackColor = Color.MediumPurple; RichTextClientPub.SelectedText = Time.NowTime() + " " + "Server Message: " + message + Environment.NewLine; _CursorPosition = RichTextClientPub.SelectionStart; }))); ++ClientStatistics.ServerMessage; if (FrmStatisticsUpdateEvent != null) { FrmStatisticsUpdateEvent.Invoke(StatisticsEntry.ServerMessage); } }
// Public Chat Send button private void BtnSend_Click(object sender, EventArgs e) { if (TextBoxPubMsg.Text.Length <= 0) { return; } ClientNetworkEngine.SendMessage(TextBoxPubMsg.Text); // Reset the TextBoxPubMsg TextBoxPubMsg.Text = null; // Update statistics ++ClientStatistics.MessagesSent; if (FrmStatisticsUpdateEvent != null) { FrmStatisticsUpdateEvent.Invoke(StatisticsEntry.MessageSent); } }
// Private message private void PrivateMessage(string clientName, string clientNamePrivate, string message) { if (TabPagePrivateChatReceiveClientEvent != null) { TabPagePrivateChatReceiveClientEvent.Invoke(clientName, clientNamePrivate, message, TabPagePrivateChatClient.TabCommand.Message); } if (Client.Name == clientNamePrivate) { ++ClientStatistics.MessagesPrivateReceived; FrmStatisticsUpdateEvent.Invoke(StatisticsEntry.MessagePrivateReceived); return; } ++ClientStatistics.MessagesPrivateSent; if (FrmStatisticsUpdateEvent != null) { FrmStatisticsUpdateEvent.Invoke(StatisticsEntry.MessagePrivateSent); } }
// Image message private void ImageMessage(string clientName, string clientNamePrivate, Image img) { if (clientNamePrivate != null) { if (Client.Name == clientName) { ++ClientStatistics.ImagesPrivateSent; if (FrmStatisticsUpdateEvent != null) { FrmStatisticsUpdateEvent.Invoke(StatisticsEntry.ImagesPrivateSent); } // Let the user know that the private photo he sent went thro if (TabPagePrivateChatReceiveClientEvent != null) { TabPagePrivateChatReceiveClientEvent.Invoke(clientName, null, null, TabPagePrivateChatClient.TabCommand.ImageMessageSent); } return; } // Show the photo to the receiving user ++ClientStatistics.ImagesPrivateReceived; if (FrmStatisticsUpdateEvent != null) { FrmStatisticsUpdateEvent.Invoke(StatisticsEntry.ImagesPrivateReceived); } _FrmClientImages.NewImage(img, clientName + " Private"); if (TabPagePrivateChatReceiveClientEvent != null) { TabPagePrivateChatReceiveClientEvent.Invoke(clientName, null, null, TabPagePrivateChatClient.TabCommand.ImageMessage); } if (_FrmClientImages.Visible == false) { if (InvokeRequired) { BeginInvoke(new MethodInvoker(delegate { _FrmClientImages.Visible = true; _FrmClientImages.BringToFront(); })); } else { _FrmClientImages.Visible = true; _FrmClientImages.BringToFront(); } } return; } if (Client.Name == clientName) { ++ClientStatistics.ImagesSent; if (FrmStatisticsUpdateEvent != null) { FrmStatisticsUpdateEvent.Invoke(StatisticsEntry.ImagesSent); } Invoke(new Action((delegate { RichTextClientPub.SelectionStart = _CursorPosition; RichTextClientPub.SelectionColor = Color.Black; RichTextClientPub.SelectionBackColor = Color.Yellow; RichTextClientPub.SelectedText = Time.NowTime() + " " + " ImageMessage sent successfully" + Environment.NewLine; _CursorPosition = RichTextClientPub.SelectionStart; }))); return; } ++ClientStatistics.ImagesReceived; if (FrmStatisticsUpdateEvent != null) { FrmStatisticsUpdateEvent.Invoke(StatisticsEntry.ImagesReceived); } _FrmClientImages.NewImage(img, clientName); if (_FrmClientImages.Visible == false) { if (InvokeRequired) { BeginInvoke(new MethodInvoker(delegate { _FrmClientImages.Visible = true; _FrmClientImages.BringToFront(); })); } else { _FrmClientImages.Visible = true; _FrmClientImages.BringToFront(); } } }