Skip to content

Commit b9fabfc

Browse files
committed
UserControl
1 parent 04b4806 commit b9fabfc

21 files changed

+998
-574
lines changed

NetDebug/App.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@
44
xmlns:local="clr-namespace:MeowType.NetDebug"
55
StartupUri="MainWindow.xaml">
66
<Application.Resources>
7-
7+
<FontFamily x:Key="FiraCodeLight">pack://application:,,,/#Fira Code Light</FontFamily>
88
</Application.Resources>
99
</Application>

NetDebug/FiraCode-Light.ttf

270 KB
Binary file not shown.

NetDebug/LocalIP.xaml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<UserControl x:Class="MeowType.NetDebug.LocalIP"
2+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
5+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
6+
xmlns:local="clr-namespace:MeowType.NetDebug"
7+
mc:Ignorable="d"
8+
d:DesignHeight="50" d:DesignWidth="250">
9+
<Grid>
10+
<Grid.RowDefinitions>
11+
<RowDefinition Height="1*"></RowDefinition>
12+
<RowDefinition Height="1*"></RowDefinition>
13+
</Grid.RowDefinitions>
14+
<Label Grid.Row="0">Local IP</Label>
15+
<ComboBox Grid.Row="1" IsEditable="True" Name="Local_ip" SelectedIndex="0" Loaded="Local_ip_Loaded">
16+
<Label Name="Local_ip_localhost" ToolTip="127.0.0.1">localhost</Label>
17+
</ComboBox>
18+
</Grid>
19+
</UserControl>

NetDebug/LocalIP.xaml.cs

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Net;
5+
using System.Text;
6+
using System.Threading.Tasks;
7+
using System.Windows;
8+
using System.Windows.Controls;
9+
using System.Windows.Data;
10+
using System.Windows.Documents;
11+
using System.Windows.Input;
12+
using System.Windows.Media;
13+
using System.Windows.Media.Imaging;
14+
using System.Windows.Navigation;
15+
using System.Windows.Shapes;
16+
17+
namespace MeowType.NetDebug
18+
{
19+
20+
/// <summary>
21+
/// LocalIP.xaml 的交互逻辑
22+
/// </summary>
23+
public partial class LocalIP : UserControl
24+
{
25+
public LocalIP()
26+
{
27+
InitializeComponent();
28+
}
29+
30+
public IPAddress Ip => Local_ip.Text.ParseIp();
31+
32+
private void Local_ip_Loaded(object sender, RoutedEventArgs e)
33+
{
34+
Local_ip.Items.Clear();
35+
var host = Dns.GetHostEntry(Dns.GetHostName());
36+
foreach (var ip in host.AddressList.Select(ip => ip.ToString()).Distinct())
37+
{
38+
Local_ip.Items.Add(ip);
39+
}
40+
Local_ip.Items.Insert(0, Local_ip_localhost);
41+
Local_ip.SelectedIndex = 0;
42+
}
43+
}
44+
}

NetDebug/LocalPort.xaml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<UserControl x:Class="MeowType.NetDebug.LocalPort"
2+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
5+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
6+
xmlns:local="clr-namespace:MeowType.NetDebug"
7+
mc:Ignorable="d"
8+
d:DesignHeight="50" d:DesignWidth="250">
9+
<Grid>
10+
<Grid.RowDefinitions>
11+
<RowDefinition Height="1*"></RowDefinition>
12+
<RowDefinition Height="1*"></RowDefinition>
13+
</Grid.RowDefinitions>
14+
<Label Grid.Row="0">Local Port</Label>
15+
<ComboBox Grid.Row="1" IsEditable="True" Name="Local_port" SelectedIndex="0" Loaded="Local_port_Loaded">
16+
<Label Name="Local_port_random">random</Label>
17+
</ComboBox>
18+
</Grid>
19+
</UserControl>

NetDebug/LocalPort.xaml.cs

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
using System.Windows;
7+
using System.Windows.Controls;
8+
using System.Windows.Data;
9+
using System.Windows.Documents;
10+
using System.Windows.Input;
11+
using System.Windows.Media;
12+
using System.Windows.Media.Imaging;
13+
using System.Windows.Navigation;
14+
using System.Windows.Shapes;
15+
16+
namespace MeowType.NetDebug
17+
{
18+
using static Utils;
19+
20+
/// <summary>
21+
/// LocalPort.xaml 的交互逻辑
22+
/// </summary>
23+
public partial class LocalPort : UserControl
24+
{
25+
public LocalPort()
26+
{
27+
InitializeComponent();
28+
}
29+
30+
public string DefaultPort
31+
{
32+
get => (string)GetValue(DefaultPortProperty);
33+
set => SetValue(DefaultPortProperty, value);
34+
}
35+
36+
public ushort? Port
37+
{
38+
get
39+
{
40+
if (Local_port.Text.ToLower() != "random")
41+
{
42+
try { return Convert.ToUInt16(Local_port.Text); }
43+
catch
44+
{
45+
Local_port.Text = "Not A Port";
46+
return null;
47+
}
48+
}
49+
else { return 0; }
50+
}
51+
set => Local_port.Text = value.HasValue? $"{value}" : "random";
52+
}
53+
54+
private void Local_port_Loaded(object sender, RoutedEventArgs e)
55+
{
56+
Local_port.Text = DefaultPort;
57+
}
58+
}
59+
}

NetDebug/MainWindow.xaml

Lines changed: 3 additions & 108 deletions
Original file line numberDiff line numberDiff line change
@@ -5,113 +5,8 @@
55
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
66
xmlns:local="clr-namespace:MeowType.NetDebug"
77
mc:Ignorable="d"
8-
Title="Net Debug" Height="450" Width="800" MinHeight="450" MinWidth="800" FontFamily="Consolas, Fira Code">
9-
<Grid Margin="5">
10-
<Grid.ColumnDefinitions>
11-
<ColumnDefinition MinWidth="200" Width="0.5*" MaxWidth="300"></ColumnDefinition>
12-
<ColumnDefinition Width="1*"></ColumnDefinition>
13-
</Grid.ColumnDefinitions>
14-
<Grid Grid.Column="0">
15-
<TabControl>
16-
<TabItem Name="Tab_Tcp_Server" Header="Tcp Server">
17-
<Grid Background="#FFE5E5E5"/>
18-
</TabItem>
19-
<TabItem Name="Tab_Tcp_Client" Header="Tcp Client">
20-
<Grid Background="#FFE5E5E5"/>
21-
</TabItem>
22-
<TabItem Name="Tab_Udp" Header="Udp" IsSelected="True">
23-
<Grid Margin="10,0">
24-
<Grid.RowDefinitions>
25-
<RowDefinition Height="50"></RowDefinition>
26-
<RowDefinition Height="50"></RowDefinition>
27-
<RowDefinition Height="100"></RowDefinition>
28-
<RowDefinition Height="50"></RowDefinition>
29-
<RowDefinition Height="50"></RowDefinition>
30-
<RowDefinition Height="50"></RowDefinition>
31-
</Grid.RowDefinitions>
32-
<Grid Grid.Row="0">
33-
<Grid.RowDefinitions>
34-
<RowDefinition Height="1*"></RowDefinition>
35-
<RowDefinition Height="1*"></RowDefinition>
36-
</Grid.RowDefinitions>
37-
<Label Grid.Row="0">Local IP</Label>
38-
<ComboBox Grid.Row="1" IsEditable="True" Name="UDP_Local_ip" SelectedIndex="0" Loaded="UDP_Local_ip_Loaded">
39-
<Label Name="UDP_Local_ip_localhost" ToolTip="127.0.0.1">localhost</Label>
40-
</ComboBox>
41-
</Grid>
42-
<Grid Grid.Row="1">
43-
<Grid.RowDefinitions>
44-
<RowDefinition Height="1*"></RowDefinition>
45-
<RowDefinition Height="1*"></RowDefinition>
46-
</Grid.RowDefinitions>
47-
<Label Grid.Row="0">Local Port</Label>
48-
<TextBox Grid.Row="1" Name="UDP_Local_port">12345</TextBox>
49-
</Grid>
50-
<Grid Grid.Row="2" Margin="0,10">
51-
<Grid.RowDefinitions>
52-
<RowDefinition Height="1*"></RowDefinition>
53-
<RowDefinition Height="1*"></RowDefinition>
54-
<RowDefinition Height="1*"></RowDefinition>
55-
<RowDefinition Height="1*"></RowDefinition>
56-
</Grid.RowDefinitions>
57-
<RadioButton Name="UDP_type_defalut" GroupName="UDP_type" IsChecked="True">Default</RadioButton>
58-
<RadioButton Name="UDP_type_broadcast" GroupName="UDP_type" Grid.Row="1" Checked="UDP_type_broadcast_Checked" Unchecked="UDP_type_broadcast_UnChecked">Broadcast</RadioButton>
59-
<RadioButton Name="UDP_type_multicast" GroupName="UDP_type" Grid.Row="2" Checked="UDP_type_multicast_Checked" Unchecked="UDP_type_multicast_Unchecked">Multicast</RadioButton>
60-
<ComboBox Grid.Row="3" IsEditable="True" Name="UDP_multicast_ip" SelectedIndex="0" Loaded="UDP_Target_ip_Loaded" Margin="20,0,0,0">
61-
<Label>224.0.0.0</Label>
62-
</ComboBox>
63-
</Grid>
64-
<Button Name="UDP_button" Grid.Row="3" Margin="20,5" Click="Open_Button_Click" FontSize="16">Open</Button>
65-
<Grid Grid.Row="4">
66-
<Grid.RowDefinitions>
67-
<RowDefinition Height="1*"></RowDefinition>
68-
<RowDefinition Height="1*"></RowDefinition>
69-
</Grid.RowDefinitions>
70-
<Label Grid.Row="0">Target IP</Label>
71-
<ComboBox Grid.Row="1" IsEditable="True" Name="UDP_Target_ip" SelectedIndex="0" Loaded="UDP_Target_ip_Loaded">
72-
<Label Name="UDP_Target_ip_localhost" ToolTip="127.0.0.1">localhost</Label>
73-
<Label Name="UDP_Target_ip_broadcast" ToolTip="255.255.255.255">broadcast</Label>
74-
</ComboBox>
75-
</Grid>
76-
<Grid Grid.Row="5">
77-
<Grid.RowDefinitions>
78-
<RowDefinition Height="1*"></RowDefinition>
79-
<RowDefinition Height="1*"></RowDefinition>
80-
</Grid.RowDefinitions>
81-
<Label Grid.Row="0">Target Port</Label>
82-
<TextBox Grid.Row="1" Name="UDP_Target_port">12345</TextBox>
83-
</Grid>
84-
</Grid>
85-
</TabItem>
86-
<TabItem Name="Tab_Custom" Header="Custom">
87-
88-
</TabItem>
89-
</TabControl>
90-
</Grid>
91-
<Grid Grid.Column="1">
92-
<Grid.RowDefinitions>
93-
<RowDefinition Height="1*"></RowDefinition>
94-
<RowDefinition Height="60"></RowDefinition>
95-
</Grid.RowDefinitions>
96-
<RichTextBox Grid.Row="0" Name="MsgBox" Margin="10,0,0,0" VerticalScrollBarVisibility="Auto" FontFamily="Consolas, Fira Code Light" IsReadOnly="True" Loaded="MsgBox_Loaded"/>
97-
<Grid Grid.Row="1" Margin="10,5,0,0">
98-
<Grid.ColumnDefinitions>
99-
<ColumnDefinition Width="50"></ColumnDefinition>
100-
<ColumnDefinition Width="1*"></ColumnDefinition>
101-
<ColumnDefinition Width="0.25*" MinWidth="50" MaxWidth="120"></ColumnDefinition>
102-
</Grid.ColumnDefinitions>
103-
<Grid Grid.Column="0">
104-
<Grid.RowDefinitions>
105-
<RowDefinition Height="1*"></RowDefinition>
106-
<RowDefinition Height="1*"></RowDefinition>
107-
</Grid.RowDefinitions>
108-
<Button Grid.Row="0" Click="Clear_Button_Click" Margin="0,0,0,2.5">Clear↑</Button>
109-
<Button Grid.Row="1" Click="Clear_Send_Button_Click" Margin="0,2.5,0,0">Clear→</Button>
110-
</Grid>
111-
<RichTextBox Name="Send_Msg" Grid.Column="1" Margin="5,0" Keyboard.KeyUp="Send_Msg_KeyUp"/>
112-
<Button Name="Send_Button" Grid.Column="2" Click="Send_Button_Click" IsEnabled="False" FontSize="20">Send</Button>
113-
</Grid>
114-
</Grid>
115-
8+
Title="Net Debug" Height="450" Width="800" MinHeight="250" MinWidth="600" FontFamily="Consolas, Fira Code">
9+
<Grid>
10+
<local:Udp></local:Udp>
11611
</Grid>
11712
</Window>

0 commit comments

Comments
 (0)