11using System ;
22using System . Collections . Generic ;
3+ using System . ComponentModel ;
34using System . Drawing ;
45using System . Windows . Forms ;
56
67namespace QpTestClient . Controls
78{
89 public partial class AotPropertyGrid : UserControl
910 {
11+ private List < Control > pnlPropertyControls = new List < Control > ( ) ;
1012 private List < Label > propertyLabelList = new List < Label > ( ) ;
1113
14+ private bool _ReadOnly = false ;
15+ [ DesignerSerializationVisibility ( DesignerSerializationVisibility . Hidden ) ]
16+ public bool ReadOnly
17+ {
18+ get { return _ReadOnly ; }
19+ set
20+ {
21+ _ReadOnly = value ;
22+ travelChild ( pnlProperty , control =>
23+ {
24+ if ( control is TextBoxBase textBoxBase )
25+ {
26+ textBoxBase . ReadOnly = value ;
27+ }
28+ else if ( control is ButtonBase buttonBase )
29+ {
30+ buttonBase . Enabled = ! value ;
31+ }
32+ else if ( control is ListControl listControl )
33+ {
34+ listControl . Enabled = ! value ;
35+ }
36+ } ) ;
37+ }
38+ }
39+
40+ private void travelChild ( Control control , Action < Control > action )
41+ {
42+ action ( control ) ;
43+ foreach ( Control child in control . Controls )
44+ {
45+ travelChild ( child , action ) ;
46+ }
47+ }
48+
1249 public AotPropertyGrid ( )
1350 {
1451 InitializeComponent ( ) ;
@@ -39,7 +76,7 @@ public void RegisterGroup(string groupName)
3976 groupLabel . Text = $ "∇ { groupName } ";
4077
4178 var enterGroup = false ;
42- foreach ( Control control in flp . Controls )
79+ foreach ( Control control in pnlPropertyControls )
4380 {
4481 if ( enterGroup )
4582 {
@@ -54,22 +91,18 @@ public void RegisterGroup(string groupName)
5491 }
5592 }
5693 } ;
57-
58-
59- flp . Controls . Add ( groupLabel ) ;
94+ pnlPropertyControls . Add ( groupLabel ) ;
6095 }
6196
6297 private Label createPropertyLabel ( string propertyName , string propertyDescription )
6398 {
6499 var label = new Label ( ) ;
65- label . BackColor = System . Drawing . SystemColors . ControlLightLight ;
100+ label . BackColor = SystemColors . ControlLightLight ;
66101 label . BorderStyle = BorderStyle . FixedSingle ;
67102 label . Dock = DockStyle . Left ;
68- label . Location = new System . Drawing . Point ( 0 , 0 ) ;
69103 label . Margin = new Padding ( 0 ) ;
70- label . MinimumSize = new System . Drawing . Size ( 180 , 30 ) ;
71- label . Size = new System . Drawing . Size ( 180 , 38 ) ;
72- label . TabIndex = 0 ;
104+ label . MinimumSize = new Size ( 180 , 30 ) ;
105+ label . Size = new Size ( 180 , 38 ) ;
73106 label . Text = propertyName ;
74107 label . Click += ( _ , _ ) =>
75108 {
@@ -83,8 +116,7 @@ private TextBox createPropertyTextBox(string propertyName, string propertyDescri
83116 {
84117 var textBox = new TextBox ( ) ;
85118 textBox . BorderStyle = BorderStyle . FixedSingle ;
86- textBox . Dock = DockStyle . Fill ;
87- textBox . Location = new Point ( 180 , 0 ) ;
119+ textBox . Dock = DockStyle . Top ;
88120 textBox . Margin = new Padding ( 0 ) ;
89121 textBox . Size = new Size ( 698 , 38 ) ;
90122 textBox . GotFocus += ( _ , _ ) =>
@@ -97,26 +129,26 @@ private TextBox createPropertyTextBox(string propertyName, string propertyDescri
97129
98130 private CheckBox createPropertyCheckBox ( string propertyName , string propertyDescription )
99131 {
100- var checkBox = new CheckBox ( ) ;
101- checkBox . BackColor = System . Drawing . SystemColors . ControlLightLight ;
102- checkBox . Dock = System . Windows . Forms . DockStyle . Fill ;
103- checkBox . Location = new System . Drawing . Point ( 0 , 0 ) ;
104- checkBox . Padding = new System . Windows . Forms . Padding ( 10 , 0 , 0 , 0 ) ;
105- checkBox . Size = new System . Drawing . Size ( 696 , 36 ) ;
132+ var checkBox = new CheckBox ( ) ;
133+ checkBox . BackColor = SystemColors . ControlLightLight ;
134+ checkBox . Dock = DockStyle . Top ;
135+ checkBox . Location = new Point ( 0 , 0 ) ;
136+ checkBox . Padding = new Padding ( 10 , 0 , 0 , 0 ) ;
137+ checkBox . Size = new Size ( 696 , 36 ) ;
106138 checkBox . UseVisualStyleBackColor = false ;
107139 return checkBox ;
108140 }
109141
110142
111143 private ComboBox createPropertyComboBox ( string propertyName , string propertyDescription )
112144 {
113- var comboBox = new ComboBox ( ) ;
114- comboBox . Dock = System . Windows . Forms . DockStyle . Fill ;
115- comboBox . DropDownStyle = System . Windows . Forms . ComboBoxStyle . DropDownList ;
116- comboBox . FlatStyle = System . Windows . Forms . FlatStyle . Flat ;
145+ var comboBox = new ComboBox ( ) ;
146+ comboBox . Dock = DockStyle . Top ;
147+ comboBox . DropDownStyle = ComboBoxStyle . DropDownList ;
148+ comboBox . FlatStyle = FlatStyle . Flat ;
117149 comboBox . FormattingEnabled = true ;
118- comboBox . Location = new System . Drawing . Point ( 0 , 0 ) ;
119- comboBox . Size = new System . Drawing . Size ( 696 , 39 ) ;
150+ comboBox . Location = new Point ( 0 , 0 ) ;
151+ comboBox . Size = new Size ( 696 , 39 ) ;
120152 return comboBox ;
121153 }
122154
@@ -126,15 +158,15 @@ private void addPropertyControl(Label label1, Control control1)
126158 LinkControl ( label1 , control1 ) ;
127159
128160 var panel1 = new Panel ( ) ;
161+ panel1 . AutoSize = true ;
129162 panel1 . Margin = new Padding ( 0 ) ;
130163 panel1 . Controls . Add ( control1 ) ;
131164 panel1 . Controls . Add ( label1 ) ;
132165 panel1 . Padding = new Padding ( 0 ) ;
133166 panel1 . Dock = DockStyle . Top ;
134- panel1 . Location = new System . Drawing . Point ( 0 , 40 ) ;
135- panel1 . Size = new System . Drawing . Size ( 878 , 38 ) ;
167+ panel1 . Size = new Size ( 878 , 38 ) ;
136168
137- flp . Controls . Add ( panel1 ) ;
169+ pnlPropertyControls . Add ( panel1 ) ;
138170 }
139171
140172
@@ -222,6 +254,22 @@ public void RegisterProperty(string propertyName, string propertyDescription, Fu
222254 addPropertyControl ( createPropertyLabel ( propertyName , propertyDescription ) , checkBox ) ;
223255 }
224256
257+ /// <summary>
258+ /// 生成控件
259+ /// </summary>
260+ public void GenerateControls ( )
261+ {
262+ for ( var i = pnlPropertyControls . Count - 1 ; i >= 0 ; i -- )
263+ {
264+ pnlProperty . Controls . Add ( pnlPropertyControls [ i ] ) ;
265+ }
266+ }
267+
268+ private void AotPropertyGrid_Load ( object sender , EventArgs e )
269+ {
270+
271+ }
272+
225273 public void RegisterProperty < TEnum > ( string propertyName , string propertyDescription , Func < TEnum > getValueHandler , Action < TEnum > setValueHandler )
226274 where TEnum : struct , Enum
227275 {
0 commit comments