コード例 #1
0
        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();
        }
コード例 #2
0
ファイル: ChatWindow.cs プロジェクト: Jibin1/Chat-Room
 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.");
     }
 }
コード例 #3
0
        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();
        }
コード例 #4
0
ファイル: ChatWindow.cs プロジェクト: Jibin1/Chat-Room
        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
                {
                }
            }
        }
コード例 #5
0
        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();
            }
        }