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

This commit is contained in:
dathlin
2017-07-16 20:18:47 +08:00
parent 1798018edd
commit ea6c207bf0
7 changed files with 78 additions and 42 deletions

View File

@@ -163,16 +163,18 @@
</Grid> </Grid>
</Grid> </Grid>
<Grid Width="100" DockPanel.Dock="Left"> <Grid Width="180" DockPanel.Dock="Left">
<Border BorderThickness="0,1,1,1" BorderBrush="DarkGray" Padding="5"> <GroupBox Header="系统信息" Margin="2,5,0,0">
<StackPanel> <Grid>
<TextBlock>随便放点什么东西</TextBlock> <StackPanel>
<Button Style="{StaticResource MaterialDesignRaisedLightButton}" Grid.Column="1" Width="60" VerticalAlignment="Center" <TextBlock>随便放点什么东西</TextBlock>
<Button Style="{StaticResource MaterialDesignRaisedLightButton}" Grid.Column="1" Width="60" VerticalAlignment="Center"
Click="Button_BackMain_Click"> Click="Button_BackMain_Click">
主页 主页
</Button> </Button>
</StackPanel> </StackPanel>
</Border> </Grid>
</GroupBox>
</Grid> </Grid>

View File

@@ -290,6 +290,7 @@ namespace 软件系统客户端Wpf
//Task.Factory.StartNew(() => messageQueue.Enqueue(message)); //Task.Factory.StartNew(() => messageQueue.Enqueue(message));
SetShowRenderControl(UIControls_Chat); SetShowRenderControl(UIControls_Chat);
UIControls_Chat.ScrollToDown();
} }
private void MenuItem头像更改_Click(object sender, RoutedEventArgs e) 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"); TextBlock_ServerTime.Text = UserClient.DateTimeServer.ToString("yyyy-MM-dd HH:mm:ss");
//label_file_count.Text = json["FileCount"].ToObject<int>().ToString(); //label_file_count.Text = json["FileCount"].ToObject<int>().ToString();
//UIControls_Chat.AddChatsHistory(sb.ToString()); UIControls_Chat.AddChatsHistory(sb.ToString());
})); }));
} }
else if (customer == CommonHeadCode.MultiNetHeadCode.) else if (customer == CommonHeadCode.MultiNetHeadCode.)
@@ -439,7 +440,7 @@ namespace 软件系统客户端Wpf
{ {
if (IsWindowShow) Dispatcher.Invoke(new Action(() => if (IsWindowShow) Dispatcher.Invoke(new Action(() =>
{ {
//UIControls_Chat?.DealwithReceive(data); UIControls_Chat?.DealwithReceive(data);
})); }));
} }
} }

View File

@@ -13,14 +13,25 @@
<RowDefinition Height="auto"></RowDefinition> <RowDefinition Height="auto"></RowDefinition>
</Grid.RowDefinitions> </Grid.RowDefinitions>
<ListBox>
<TextBox IsReadOnly="True" x:Name="TextBox_ChatHistory" VerticalScrollBarVisibility="Auto" TextWrapping="Wrap"></TextBox>
<!--<ListBox>
<ListBox.ItemTemplate> <ListBox.ItemTemplate>
<DataTemplate> <DataTemplate>
</DataTemplate> </DataTemplate>
</ListBox.ItemTemplate> </ListBox.ItemTemplate>
</ListBox> </ListBox>-->
<TextBlock Grid.Row="1" Margin="2">按Enter键发送消息</TextBlock> <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> </Grid>
</UserControl> </UserControl>

View File

@@ -2,6 +2,7 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Windows; using System.Windows;
using System.Windows.Controls; using System.Windows.Controls;
@@ -31,14 +32,14 @@ namespace 软件系统客户端Wpf.Views
public void DealwithReceive(string str) public void DealwithReceive(string str)
{ {
//richTextBox1.AppendText(str + Environment.NewLine); TextBox_ChatHistory.AppendText(str + Environment.NewLine);
//int length = str.IndexOf(Environment.NewLine) + 1; int length = str.IndexOf(Environment.NewLine) + 1;
//if (length > 0) if (length > 0)
//{ {
// richTextBox1.Select(richTextBox1.Text.Length - str.Length + 1, length); TextBox_ChatHistory.Select(TextBox_ChatHistory.Text.Length - str.Length + 1, length);
// richTextBox1.SelectionColor = Color.Blue; TextBox_ChatHistory.SelectionBrush = Brushes.Blue;
//} }
//ScrollToDown(); ScrollToDown();
} }
/// <summary> /// <summary>
/// 新增聊天的历史记录 /// 新增聊天的历史记录
@@ -46,19 +47,19 @@ namespace 软件系统客户端Wpf.Views
/// <param name="str"></param> /// <param name="str"></param>
public void AddChatsHistory(string str) public void AddChatsHistory(string str)
{ {
//richTextBox1.Text = str; TextBox_ChatHistory.Text = str;
//MatchCollection mc = Regex.Matches(str, @"\u0002.+\r\n"); MatchCollection mc = Regex.Matches(str, @"\u0002.+\r\n");
//int indexrow = 0; int indexrow = 0;
//if (str != "") if (str != "")
//{ {
// foreach (Match m in mc) foreach (Match m in mc)
// { {
// richTextBox1.Select(m.Index - indexrow * 2, m.Length - 2); TextBox_ChatHistory.Select(m.Index - indexrow * 2, m.Length - 2);
// richTextBox1.SelectionColor = Color.Blue; TextBox_ChatHistory.SelectionBrush = Brushes.Blue;
// indexrow++; indexrow++;
// } }
//} }
//ScrollToDown(); ScrollToDown();
} }
public void InputFocus() public void InputFocus()
@@ -66,15 +67,36 @@ namespace 软件系统客户端Wpf.Views
//textBox1.Focus(); //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>
///// </summary> /// 光标滚动到最底端
//public void ScrollToDown() /// </summary>
//{ public void ScrollToDown()
// richTextBox1.SelectionStart = richTextBox1.Text.Length; {
// richTextBox1.ScrollToCaret(); TextBox_ChatHistory.ScrollToEnd();
//} }
} }
} }

Binary file not shown.

Before

Width:  |  Height:  |  Size: 106 KiB

After

Width:  |  Height:  |  Size: 112 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 106 KiB

After

Width:  |  Height:  |  Size: 111 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 104 KiB