public void DealwithReceive(string str) { TextBox_ChatHistory.AppendText(str + Environment.NewLine); int length = str.IndexOf(Environment.NewLine) + 1; if (length > 0) { TextBox_ChatHistory.Select(TextBox_ChatHistory.Text.Length - str.Length + 1, length); TextBox_ChatHistory.SelectionBrush = Brushes.Blue; } ScrollToDown(); }
/// <summary> /// 新增聊天的历史记录 /// </summary> /// <param name="str"></param> public void AddChatsHistory(string str) { TextBox_ChatHistory.Text = str; MatchCollection mc = Regex.Matches(str, @"\u0002.+\r\n"); int indexrow = 0; if (str != "") { foreach (Match m in mc) { TextBox_ChatHistory.Select(m.Index - indexrow * 2, m.Length - 2); TextBox_ChatHistory.SelectionBrush = Brushes.Blue; indexrow++; } } ScrollToDown(); }