Skip to content

Commit 9c38b42

Browse files
committed
增加ClientOptionsControl抽象类。
1 parent 7705baf commit 9c38b42

12 files changed

+770
-13
lines changed
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
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.Forms;
7+
using System.ComponentModel;
8+
9+
namespace QpTestClient.Controls.ClientOptions
10+
{
11+
public abstract class ClientOptionsControl : UserControl
12+
{
13+
private bool _ReadOnly = false;
14+
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
15+
public bool ReadOnly
16+
{
17+
get { return _ReadOnly; }
18+
set
19+
{
20+
_ReadOnly = value;
21+
travelChild(this, control =>
22+
{
23+
if(control is TextBoxBase textBoxBase)
24+
{
25+
textBoxBase.ReadOnly = value;
26+
}
27+
else if(control is ButtonBase buttonBase)
28+
{
29+
buttonBase.Enabled = !value;
30+
}
31+
else if (control is ListControl listControl)
32+
{
33+
listControl.Enabled = !value;
34+
}
35+
});
36+
}
37+
}
38+
39+
private void travelChild(Control control,Action<Control> action)
40+
{
41+
action(control);
42+
foreach (Control child in control.Controls)
43+
{
44+
travelChild(child, action);
45+
}
46+
}
47+
}
48+
}

QpTestClient/Controls/ClientOptions/ClientOptionsControlUtils.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,13 @@ public static void LinkControl(Label label, Control control)
7575
{
7676
label.Click += (_, _) =>
7777
{
78-
ActiveLabel(label);
79-
if (!control.Focused)
78+
if (control.CanFocus)
8079
{
81-
control.Focus();
80+
ActiveLabel(label);
81+
if (!control.Focused)
82+
{
83+
control.Focus();
84+
}
8285
}
8386
};
8487
control.GotFocus += (_, _) =>

QpTestClient/Controls/ClientOptions/PipelineClientOptionsControl.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
namespace QpTestClient.Controls.ClientOptions
1515
{
16-
public partial class PipelineClientOptionsControl : UserControl
16+
public partial class PipelineClientOptionsControl : ClientOptionsControl
1717
{
1818
public PipelineClientOptionsControl()
1919
{

QpTestClient/Controls/ClientOptions/SerialPortClientOptionsControl.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
namespace QpTestClient.Controls.ClientOptions
1717
{
18-
public partial class SerialPortClientOptionsControl : UserControl
18+
public partial class SerialPortClientOptionsControl : ClientOptionsControl
1919
{
2020
public SerialPortClientOptionsControl()
2121
{

QpTestClient/Controls/ClientOptions/TcpClientOptionsControl.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
namespace QpTestClient.Controls.ClientOptions
1414
{
15-
public partial class TcpClientOptionsControl : UserControl
15+
public partial class TcpClientOptionsControl : ClientOptionsControl
1616
{
1717
public TcpClientOptionsControl()
1818
{

0 commit comments

Comments
 (0)