Skip to content

Commit 7705baf

Browse files
committed
完成串口连接类型参数控件改造。
1 parent 969061e commit 7705baf

File tree

7 files changed

+959
-14
lines changed

7 files changed

+959
-14
lines changed

QpTestClient/ConnectForm.Designer.cs

Lines changed: 7 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

QpTestClient/Controls/ClientOptions/ClientOptionsControlUtils.cs

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@ public class ClientOptionsControlUtils
1414
public static void BindString(TextBox textBox, Func<string> getValueHandler, Action<string> setValueHandler)
1515
{
1616
textBox.Text = getValueHandler();
17-
textBox.TextChanged += (sender2, e2) => setValueHandler(textBox.Text);
17+
textBox.TextChanged += (_, _) => setValueHandler(textBox.Text);
1818
}
1919

2020
public static void BindInt32(TextBox textBox, Func<int> getValueHandler, Action<int> setValueHandler)
2121
{
2222
textBox.Text = getValueHandler().ToString();
23-
textBox.TextChanged += (sender2, e2) =>
23+
textBox.TextChanged += (_, _) =>
2424
{
2525
if (int.TryParse(textBox.Text, out var v))
2626
setValueHandler(v);
@@ -32,7 +32,7 @@ public static void BindInt32(TextBox textBox, Func<int> getValueHandler, Action<
3232
public static void BindInt32(TextBox textBox, Func<int?> getValueHandler, Action<int?> setValueHandler)
3333
{
3434
textBox.Text = getValueHandler()?.ToString();
35-
textBox.TextChanged += (sender2, e2) =>
35+
textBox.TextChanged += (_, _) =>
3636
{
3737
var text = textBox.Text;
3838
if (string.IsNullOrEmpty(text))
@@ -47,7 +47,16 @@ public static void BindInt32(TextBox textBox, Func<int?> getValueHandler, Action
4747
public static void BindBoolean(CheckBox checkBox, Func<bool> getValueHandler, Action<bool> setValueHandler)
4848
{
4949
checkBox.Checked = getValueHandler();
50-
checkBox.CheckedChanged += (sender2, e2) => setValueHandler(checkBox.Checked);
50+
checkBox.CheckedChanged += (_, _) => setValueHandler(checkBox.Checked);
51+
}
52+
53+
public static void BindEnum<TEnum>(ComboBox comboBox, Func<TEnum> getValueHandler, Action<TEnum> setValueHandler)
54+
where TEnum : struct, Enum
55+
{
56+
foreach (var item in Enum.GetValues<TEnum>())
57+
comboBox.Items.Add(item);
58+
comboBox.SelectedItem = getValueHandler();
59+
comboBox.SelectedIndexChanged += (_, _) => setValueHandler((TEnum)comboBox.SelectedItem);
5160
}
5261

5362
private static void ActiveLabel(Label label)
@@ -64,19 +73,19 @@ private static void DeactiveLabel(Label label)
6473

6574
public static void LinkControl(Label label, Control control)
6675
{
67-
label.Click += (sender, e) =>
76+
label.Click += (_, _) =>
6877
{
6978
ActiveLabel(label);
7079
if (!control.Focused)
7180
{
7281
control.Focus();
7382
}
7483
};
75-
control.GotFocus += (sender, e) =>
84+
control.GotFocus += (_, _) =>
7685
{
7786
ActiveLabel(label);
7887
};
79-
control.LostFocus += (sender, e) =>
88+
control.LostFocus += (_, _) =>
8089
{
8190
DeactiveLabel(label);
8291
};

0 commit comments

Comments
 (0)