提交 ea6c207b 编写于 作者: Richard__Hu's avatar Richard__Hu

添加聊天功能,主界面修改一点显示

上级 1798018e
......@@ -163,16 +163,18 @@
</Grid>
</Grid>
<Grid Width="100" DockPanel.Dock="Left">
<Border BorderThickness="0,1,1,1" BorderBrush="DarkGray" Padding="5">
<StackPanel>
<TextBlock>随便放点什么东西</TextBlock>
<Button Style="{StaticResource MaterialDesignRaisedLightButton}" Grid.Column="1" Width="60" VerticalAlignment="Center"
<Grid Width="180" DockPanel.Dock="Left">
<GroupBox Header="系统信息" Margin="2,5,0,0">
<Grid>
<StackPanel>
<TextBlock>随便放点什么东西</TextBlock>
<Button Style="{StaticResource MaterialDesignRaisedLightButton}" Grid.Column="1" Width="60" VerticalAlignment="Center"
Click="Button_BackMain_Click">
主页
</Button>
</StackPanel>
</Border>
主页
</Button>
</StackPanel>
</Grid>
</GroupBox>
</Grid>
......
......@@ -290,6 +290,7 @@ namespace 软件系统客户端Wpf
//Task.Factory.StartNew(() => messageQueue.Enqueue(message));
SetShowRenderControl(UIControls_Chat);
UIControls_Chat.ScrollToDown();
}
private void MenuItem头像更改_Click(object sender, RoutedEventArgs e)
......@@ -425,7 +426,7 @@ namespace 软件系统客户端Wpf
{
TextBlock_ServerTime.Text = UserClient.DateTimeServer.ToString("yyyy-MM-dd HH:mm:ss");
//label_file_count.Text = json["FileCount"].ToObject<int>().ToString();
//UIControls_Chat.AddChatsHistory(sb.ToString());
UIControls_Chat.AddChatsHistory(sb.ToString());
}));
}
else if (customer == CommonHeadCode.MultiNetHeadCode.文件总数量)
......@@ -439,7 +440,7 @@ namespace 软件系统客户端Wpf
{
if (IsWindowShow) Dispatcher.Invoke(new Action(() =>
{
//UIControls_Chat?.DealwithReceive(data);
UIControls_Chat?.DealwithReceive(data);
}));
}
}
......
......@@ -13,14 +13,25 @@
<RowDefinition Height="auto"></RowDefinition>
</Grid.RowDefinitions>
<ListBox>
<TextBox IsReadOnly="True" x:Name="TextBox_ChatHistory" VerticalScrollBarVisibility="Auto" TextWrapping="Wrap"></TextBox>
<!--<ListBox>
<ListBox.ItemTemplate>
<DataTemplate>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</ListBox>-->
<TextBlock Grid.Row="1" Margin="2">按Enter键发送消息:</TextBlock>
<Grid Grid.Row="2">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"></ColumnDefinition>
<ColumnDefinition Width="auto"></ColumnDefinition>
</Grid.ColumnDefinitions>
<TextBox MaxLines="1" KeyDown="TextBox_KeyDown" x:Name="TextBox_Send"></TextBox>
<Button Style="{StaticResource MaterialDesignRaisedButton}" Grid.Column="1" Click="Button_Click">发送</Button>
</Grid>
</Grid>
</UserControl>
......@@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
......@@ -31,14 +32,14 @@ namespace 软件系统客户端Wpf.Views
public void DealwithReceive(string str)
{
//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();
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>
/// 新增聊天的历史记录
......@@ -46,19 +47,19 @@ namespace 软件系统客户端Wpf.Views
/// <param name="str"></param>
public void AddChatsHistory(string 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();
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();
}
public void InputFocus()
......@@ -66,15 +67,36 @@ namespace 软件系统客户端Wpf.Views
//textBox1.Focus();
}
private void Button_Click(object sender, RoutedEventArgs e)
{
if (!string.IsNullOrEmpty(TextBox_Send.Text))
{
SendString?.Invoke(TextBox_Send.Text);
TextBox_Send.Text = "";
}
}
private void TextBox_KeyDown(object sender, KeyEventArgs e)
{
//按下Enter键后进行发送数据到服务器
if (!string.IsNullOrEmpty(TextBox_Send.Text))
{
if (e.Key == Key.Enter)
{
SendString?.Invoke(TextBox_Send.Text);
TextBox_Send.Text = "";
}
}
}
///// <summary>
///// 光标滚动到最底端
///// </summary>
//public void ScrollToDown()
//{
// richTextBox1.SelectionStart = richTextBox1.Text.Length;
// richTextBox1.ScrollToCaret();
//}
/// <summary>
/// 光标滚动到最底端
/// </summary>
public void ScrollToDown()
{
TextBox_ChatHistory.ScrollToEnd();
}
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册