private void WriteChat(string name, string text) { text = _html.Replace(_emoji.Replace(text, " "), string.Empty); var start = ChatRichTextBox.Text.Length; ChatRichTextBox.Select(start, 0); ChatRichTextBox.SelectionHangingIndent = 0; ChatRichTextBox.SelectionTabs = new[] { 200 }; ChatRichTextBox.SelectedText = string.Format("{0:HH:mm:ss} ", DateTime.Now); ChatRichTextBox.Select(start, ChatRichTextBox.Text.Length - start); ChatRichTextBox.SelectionFont = new Font("Arial", 12, FontStyle.Regular); ChatRichTextBox.SelectionColor = Color.Gray; start = ChatRichTextBox.Text.Length; ChatRichTextBox.Select(start, 0); ChatRichTextBox.SelectedText = name; ChatRichTextBox.Select(start, ChatRichTextBox.Text.Length - start); ChatRichTextBox.SelectionFont = new Font("Arial", 12, FontStyle.Bold); ChatRichTextBox.SelectionColor = Color.Black; start = ChatRichTextBox.Text.Length; ChatRichTextBox.Select(start, 0); ChatRichTextBox.SelectedText = string.Concat('\t', text, '\n', '\n'); ChatRichTextBox.Select(start, ChatRichTextBox.Text.Length - start); ChatRichTextBox.SelectionFont = new Font("Arial", 12, FontStyle.Regular); ChatRichTextBox.SelectionColor = Color.Black; ChatRichTextBox.SelectionHangingIndent = 200; start = ChatRichTextBox.Text.Length; ChatRichTextBox.Select(start, 0); ChatRichTextBox.ScrollToCaret(); }
private void SendButton_Click(object sender, EventArgs e) { if (connected == true) { if (currentUser == null) { currentUser = UserTextBox.Text; sw.WriteLine(currentUser); } else { try { string message = UserTextBox.Text; Message newMessage = new Message(currentUser, message); messageList.Add(newMessage); sw.WriteLine(currentUser + ": " + message); } catch { ChatRichTextBox.AppendText("Failed to deliver message \n"); } } sw.Flush(); UserTextBox.Clear(); } else { MessageBox.Show("Not connected to server."); } }
private void on_chat_message(object sender, NetChatEventArgs eventArgs) { string textToAppend = peer.Name + ": " + eventArgs.Message; Paragraph newParagraph = new Paragraph(new Run(textToAppend)) { LineHeight = 1, Foreground = Brushes.Orange }; ChatRichTextBoxFlowDocument.Blocks.Add(newParagraph); ChatRichTextBox.ScrollToEnd(); }
public void receive() { while (true) { try { string response = sr.ReadLine(); Console.WriteLine(response); string userName = response.Substring(0, response.IndexOf(':')); string message = response.Substring(response.IndexOf(':') + 1); //Console.WriteLine("userName: "******" ,message: " + message); Message newMessage = new Message(userName, message); messageList.Add(newMessage); ChatRichTextBox.AppendText(response + " \n"); } catch { } } }
private void handleChatInput() { if (!String.IsNullOrEmpty(ChatTextInput.Text)) { //todo: put this back in when networking works again, else will crash cause I'm passing in a null peer peer.SendChat(ChatTextInput.Text); string textToAppend = humanPlayerName + ": " + ChatTextInput.Text; Paragraph newParagraph = new Paragraph(new Run(textToAppend)) { LineHeight = 1, Foreground = Brushes.Cyan }; ChatRichTextBoxFlowDocument.Blocks.Add(newParagraph); ChatRichTextBox.ScrollToEnd(); ChatTextInput.Clear(); } }