diff --git a/Client/Program.cs b/Client/Program.cs index a799e6c..e26389e 100644 --- a/Client/Program.cs +++ b/Client/Program.cs @@ -1,6 +1,7 @@ using ChatRoom.Utils; using Microsoft.Extensions.Logging; using System.CommandLine; +using System.Net; using System.Net.Sockets; using System.Reflection; using System.Text; @@ -46,7 +47,7 @@ private static async Task ChatMainAsync() ip = Console.ReadLine(); try { - await client.ConnectAsync(ip, 19132); + await client.ConnectAsync(IPAddress.TryParse(ip, out IPAddress address) ? address : IPAddress.Loopback, 19132); } catch (SocketException ex) { @@ -87,7 +88,7 @@ private static async Task ChatMainAsync() client = new(SocketType.Stream, ProtocolType.Tcp); try { - await client.ConnectAsync(ip, 19132); + await client.ConnectAsync(IPAddress.TryParse(ip, out IPAddress address) ? address : IPAddress.Loopback, 19132); } catch (SocketException) { diff --git a/ClientUI/ChatBoxHeightConverter.cs b/ClientUI/ChatBoxHeightConverter.cs new file mode 100644 index 0000000..d8f471e --- /dev/null +++ b/ClientUI/ChatBoxHeightConverter.cs @@ -0,0 +1,22 @@ +using System.Globalization; +using System.Windows.Data; + +namespace ChatRoom; + +class ChatBoxHeightConverter : IValueConverter +{ + public object Convert(object value, Type targetType, object parameter, CultureInfo culture) + { + double result = (double)value - 102; + if (result < 0) + { + return 0; + } + return result; + } + + public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) + { + throw new NotImplementedException(); + } +} diff --git a/ClientUI/ChatBoxWidthConverter.cs b/ClientUI/ChatBoxWidthConverter.cs new file mode 100644 index 0000000..cc4bf5a --- /dev/null +++ b/ClientUI/ChatBoxWidthConverter.cs @@ -0,0 +1,22 @@ +using System.Globalization; +using System.Windows.Data; + +namespace ChatRoom; + +class ChatBoxWidthConverter : IValueConverter +{ + public object Convert(object value, Type targetType, object parameter, CultureInfo culture) + { + double result = (double)value - 20; + if (result < 0) + { + return 0; + } + return result; + } + + public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) + { + throw new NotImplementedException(); + } +} diff --git a/ClientUI/InputBoxWidthConverter.cs b/ClientUI/InputBoxWidthConverter.cs new file mode 100644 index 0000000..313a611 --- /dev/null +++ b/ClientUI/InputBoxWidthConverter.cs @@ -0,0 +1,22 @@ +using System.Globalization; +using System.Windows.Data; + +namespace ChatRoom; + +class InputBoxWidthConverter : IValueConverter +{ + public object Convert(object value, Type targetType, object parameter, CultureInfo culture) + { + double result = (double)value - 125; + if (result < 0) + { + return 0; + } + return result; + } + + public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) + { + throw new NotImplementedException(); + } +} diff --git a/ClientUI/MainWindow.xaml b/ClientUI/MainWindow.xaml index 0c331ae..07dc249 100644 --- a/ClientUI/MainWindow.xaml +++ b/ClientUI/MainWindow.xaml @@ -1,10 +1,16 @@ - + Title="聊天室" Height="450" Width="800" FontFamily="Segoe UI Emoji"> + + + + + @@ -12,9 +18,9 @@ - - + +