初始化项目

This commit is contained in:
2025-12-11 11:54:05 +08:00
commit 6fb36792ed
64 changed files with 100079 additions and 0 deletions

184
SetingSerialPort.vb Normal file
View File

@@ -0,0 +1,184 @@
Imports System.IO.Ports
Public Class SetingSerialPort
Public G_Dictionary As Dictionary(Of String, (Boolean, String, Integer, String, Color)
Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click, Button3.Click, Button2.Click, Button1.Click
Dim bt As Button = CType(sender, Button)
'‘打开选色面板
Dim ColorDialog1 As New ColorDialog
ColorDialog1.ShowDialog()
'‘将选中的颜色赋值给文本的字体色
Select Case bt.Tag
Case "1"
TextBox1.ForeColor = ColorDialog1.Color
Case "2"
TextBox2.ForeColor = ColorDialog1.Color
Case "3"
TextBox3.ForeColor = ColorDialog1.Color
Case "4"
TextBox4.ForeColor = ColorDialog1.Color
End Select
End Sub
Private Sub Button5_Click(sender As Object, e As EventArgs) Handles Button5.Click
G_Dictionary.Clear()
Dim boot As Integer
'判断勾选框是否选中
'判断串口名称是否为空 port1
If String.IsNullOrEmptyport1.Text Then
MsgBox("请选择串口1名称")
Return
End If
'判断波特率是否为空
If String.IsNullOrEmptyboot1.Text Then
MsgBox("请选择串口1波特率")
Return
End If
'判断别名是否为空
If String.IsNullOrEmptyTextBox1.Text Then
MsgBox("择串口1别名为空")
Return
End If
'添加到列表中
G_Dictionary.Add("1", (CheckBox1.Checked, port1.Text, Convert.ToInt32(boot1.Text), TextBox1.Text, TextBox1.ForeColor))
If String.IsNullOrEmptyport2.Text Then
MsgBox("请选择串口2名称")
Return
End If
If String.IsNullOrEmptyboot2.Text Then
MsgBox("请选择串口2波特率")
Return
End If
If String.IsNullOrEmptyTextBox2.Text Then
MsgBox("择串口2别名为空")
Return
End If
G_Dictionary.Add("2", (CheckBox2.Checked, port2.Text, Convert.ToInt32(boot2.Text), TextBox2.Text, TextBox2.ForeColor))
If String.IsNullOrEmptyport3.Text Then
MsgBox("请选择串口3名称")
Return
End If
If String.IsNullOrEmptyboot3.Text Then
MsgBox("请选择串口3波特率")
Return
End If
If String.IsNullOrEmptyTextBox3.Text Then
MsgBox("择串口3别名为空")
Return
End If
G_Dictionary.Add("3", (CheckBox3.Checked, port3.Text, Convert.ToInt32(boot3.Text), TextBox3.Text, TextBox3.ForeColor))
If String.IsNullOrEmptyport4.Text Then
MsgBox("请选择串口4名称")
Return
End If
If String.IsNullOrEmptyboot4.Text Then
MsgBox("请选择串口4波特率")
Return
End If
If String.IsNullOrEmptyTextBox4.Text Then
MsgBox("择串口4别名为空")
Return
End If
G_Dictionary.Add("4", (CheckBox4.Checked, port4.Text, Convert.ToInt32(boot4.Text), TextBox4.Text, TextBox4.ForeColor))
'关闭窗体并返回ok
Me.DialogResult = DialogResult.OK
Me.Close()
End Sub
Private Sub SetingSerialPort_Load(sender As Object, e As EventArgs) Handles MyBase.Load
'获取串口列表
Dim portNames As String() = SerialPort.GetPortNames()
'将串口列表添加到下拉框中
port1.Items.Clear()
port2.Items.Clear()
port3.Items.Clear()
port4.Items.Clear()
port1.Items.AddRange(portNames)
port2.Items.AddRange(portNames)
port3.Items.AddRange(portNames)
port4.Items.AddRange(portNames)
If IsNothing(G_Dictionary) OrElse G_Dictionary.Count = 0 Then
G_Dictionary = New Dictionary(Of String, (Boolean, String, Integer, String, Color)
port1.SelectedIndex = 0
port2.SelectedIndex = 0
port3.SelectedIndex = 0
port4.SelectedIndex = 0
boot1.SelectedIndex = 0
boot2.SelectedIndex = 0
boot3.SelectedIndex = 0
boot4.SelectedIndex = 0
Else
For Each item In G_Dictionary
Select Case item.Key
Case "1"
CheckBox1.Checked = item.Value.Item1
If port1.Items.Contains(item.Value.Item2) Then
port1.Text = item.Value.Item2
Else
port1.SelectedIndex = 0
End If
boot1.Text = item.Value.Item3
TextBox1.Text = item.Value.Item4
TextBox1.ForeColor = item.Value.Item5
Case "2"
CheckBox2.Checked = item.Value.Item1
If port2.Items.Contains(item.Value.Item2) Then
port2.Text = item.Value.Item2
Else
port2.SelectedIndex = 0
End If
boot2.Text = item.Value.Item3
TextBox2.Text = item.Value.Item4
TextBox2.ForeColor = item.Value.Item5
Case "3"
CheckBox3.Checked = item.Value.Item1
If port3.Items.Contains(item.Value.Item2) Then
port3.Text = item.Value.Item2
Else
port3.SelectedIndex = 0
End If
boot3.Text = item.Value.Item3
TextBox3.Text = item.Value.Item4
TextBox3.ForeColor = item.Value.Item5
Case "4"
CheckBox4.Checked = item.Value.Item1
If port4.Items.Contains(item.Value.Item2) Then
port4.Text = item.Value.Item2
Else
port4.SelectedIndex = 0
End If
boot4.Text = item.Value.Item3
TextBox4.Text = item.Value.Item4
TextBox4.ForeColor = item.Value.Item5
End Select
Next
End If
End Sub
End Class