2017-05-06 12:54:57 +08:00
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using System.ComponentModel;
|
|
|
|
|
|
using System.Drawing;
|
|
|
|
|
|
using System.Data;
|
|
|
|
|
|
using System.Linq;
|
|
|
|
|
|
using System.Text;
|
|
|
|
|
|
using System.Windows.Forms;
|
2017-06-25 15:34:14 +08:00
|
|
|
|
using System.Text.RegularExpressions;
|
2017-05-06 12:54:57 +08:00
|
|
|
|
|
|
|
|
|
|
namespace 软件系统客户端模版.UIControls
|
|
|
|
|
|
{
|
|
|
|
|
|
public partial class OnlineChatRender : UserControl
|
|
|
|
|
|
{
|
2017-05-18 17:13:42 +08:00
|
|
|
|
public OnlineChatRender(Action<string> send)
|
2017-05-06 12:54:57 +08:00
|
|
|
|
{
|
|
|
|
|
|
InitializeComponent();
|
2017-05-18 17:13:42 +08:00
|
|
|
|
SendString = send;
|
2017-05-06 12:54:57 +08:00
|
|
|
|
}
|
2017-05-18 17:13:42 +08:00
|
|
|
|
|
|
|
|
|
|
private Action<string> SendString = null;
|
|
|
|
|
|
|
2017-05-13 23:00:15 +08:00
|
|
|
|
private void textBox1_KeyDown(object sender, KeyEventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
//按下Enter键后进行发送数据到服务器
|
2017-05-18 17:13:42 +08:00
|
|
|
|
if(!string.IsNullOrEmpty(textBox1.Text))
|
|
|
|
|
|
{
|
|
|
|
|
|
if (e.KeyCode == Keys.Enter)
|
|
|
|
|
|
{
|
|
|
|
|
|
SendString?.Invoke(textBox1.Text);
|
|
|
|
|
|
textBox1.Text = "";
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2017-05-13 23:00:15 +08:00
|
|
|
|
}
|
2017-05-17 22:20:52 +08:00
|
|
|
|
|
|
|
|
|
|
private void OnlineChatRender_Load(object sender, EventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
}
|
2017-05-18 17:13:42 +08:00
|
|
|
|
|
|
|
|
|
|
public void DealwithReceive(string str)
|
|
|
|
|
|
{
|
|
|
|
|
|
richTextBox1.AppendText(str + Environment.NewLine);
|
2017-06-25 15:34:14 +08:00
|
|
|
|
int length = str.IndexOf(Environment.NewLine) + 1;
|
|
|
|
|
|
if (length > 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
richTextBox1.Select(richTextBox1.Text.Length - str.Length + 1, length);
|
|
|
|
|
|
richTextBox1.SelectionColor = Color.Blue;
|
|
|
|
|
|
}
|
|
|
|
|
|
ScrollToDown();
|
2017-05-18 17:13:42 +08:00
|
|
|
|
}
|
2017-06-20 11:26:40 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 新增聊天的历史记录
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="str"></param>
|
|
|
|
|
|
public void AddChatsHistory(string str)
|
|
|
|
|
|
{
|
|
|
|
|
|
richTextBox1.Text = str;
|
2017-06-25 15:34:14 +08:00
|
|
|
|
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();
|
2017-06-20 11:26:40 +08:00
|
|
|
|
}
|
2017-05-18 17:13:42 +08:00
|
|
|
|
|
|
|
|
|
|
public void InputFocus()
|
|
|
|
|
|
{
|
|
|
|
|
|
textBox1.Focus();
|
|
|
|
|
|
}
|
2017-06-25 15:34:14 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 光标滚动到最底端
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public void ScrollToDown()
|
|
|
|
|
|
{
|
|
|
|
|
|
richTextBox1.SelectionStart = richTextBox1.Text.Length;
|
|
|
|
|
|
richTextBox1.ScrollToCaret();
|
|
|
|
|
|
}
|
2017-05-06 12:54:57 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|