实时聊天界面文字颜色更改,消息发送人进行高亮显示。

This commit is contained in:
dathlin
2017-06-25 15:34:14 +08:00
parent c38a960f34
commit 3dc6cabd10

View File

@@ -6,6 +6,7 @@ using System.Data;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Windows.Forms; using System.Windows.Forms;
using System.Text.RegularExpressions;
namespace .UIControls namespace .UIControls
{ {
@@ -40,6 +41,13 @@ namespace 软件系统客户端模版.UIControls
public void DealwithReceive(string str) public void DealwithReceive(string str)
{ {
richTextBox1.AppendText(str + Environment.NewLine); richTextBox1.AppendText(str + Environment.NewLine);
int length = str.IndexOf(Environment.NewLine) + 1;
if (length > 0)
{
richTextBox1.Select(richTextBox1.Text.Length - str.Length + 1, length);
richTextBox1.SelectionColor = Color.Blue;
}
ScrollToDown();
} }
/// <summary> /// <summary>
/// 新增聊天的历史记录 /// 新增聊天的历史记录
@@ -48,11 +56,34 @@ namespace 软件系统客户端模版.UIControls
public void AddChatsHistory(string str) public void AddChatsHistory(string str)
{ {
richTextBox1.Text = str; richTextBox1.Text = str;
MatchCollection mc = Regex.Matches(str, @"\u0002.+\r\n");
int indexrow = 0;
if (str != "")
{
foreach (Match m in mc)
{
richTextBox1.Select(m.Index - indexrow * 2, m.Length - 2);
richTextBox1.SelectionColor = Color.Blue;
indexrow++;
}
}
ScrollToDown();
} }
public void InputFocus() public void InputFocus()
{ {
textBox1.Focus(); textBox1.Focus();
} }
/// <summary>
/// 光标滚动到最底端
/// </summary>
public void ScrollToDown()
{
richTextBox1.SelectionStart = richTextBox1.Text.Length;
richTextBox1.ScrollToCaret();
}
} }
} }