1. 程式人生 > >(四十七)c#Winform自定義控制元件-樹表格(treeGrid)

(四十七)c#Winform自定義控制元件-樹表格(treeGrid)

前提

入行已經7,8年了,一直想做一套漂亮點的自定義控制元件,於是就有了本系列文章。

GitHub:https://github.com/kwwwvagaa/NetWinformControl

碼雲:https://gitee.com/kwwwvagaa/net_winform_custom_control.git

如果覺得寫的還行,請點個 star 支援一下吧

歡迎前來交流探討: 企鵝群568015492 

麻煩部落格下方點個【推薦】,謝謝

NuGet

Install-Package HZH_Controls

目錄

https://www.cnblogs.com/bfyx/p/11364884.html

用處及效果

準備工作

這個是在前面表格的基礎上,擴充套件了自定義行實現的,當然也修改了一些列表控制元件以相容

如果對前面的表格控制元件不瞭解,請移步檢視

(三十二)c#Winform自定義控制元件-表格

開始

實現樹表格的思路就是,在行控制元件中再新增一個無標題的表格控制元件,當需要顯示子節點的時候,將子節點資料載入到行裡的表格控制元件中,然後處理一下事件,讓事件可以穿透到最頂層就行了。

另外我們前面表格中的行個數是根據高度大小自動計算的,這裡就會出現問題,當出現子節點表格的時候,就會導致重算個數和高度,所有我們在表格列表控制元件增加一個屬性來禁用這個自動計算。

 

新增一個使用者控制元件,命名UCDataGridViewTreeRow,實現介面IDataGridViewRow

屬性

 1  #region 屬性
 2         public event DataGridViewEventHandler CheckBoxChangeEvent;
 3 
 4         public event DataGridViewEventHandler CellClick;
 5 
 6         public event DataGridViewEventHandler SourceChanged;
 7 
 8         public List<DataGridViewColumnEntity> Columns
 9         {
10             get;
11             set;
12         }
13 
14         public object DataSource
15         {
16             get;
17             set;
18         }
19 
20         public bool IsShowCheckBox
21         {
22             get;
23             set;
24         }
25         private bool m_isChecked;
26         public bool IsChecked
27         {
28             get
29             {
30                 return m_isChecked;
31             }
32 
33             set
34             {
35                 if (m_isChecked != value)
36                 {
37                     m_isChecked = value;
38                     (this.panCells.Controls.Find("check", false)[0] as UCCheckBox).Checked = value;
39                 }
40             }
41         }
42 
43         int m_rowHeight = 40;
44         public int RowHeight
45         {
46             get
47             {
48                 return m_rowHeight;
49             }
50             set
51             {
52                 m_rowHeight = value;
53                 this.Height = value;
54             }
55         }
56         #endregion

建構函式處理一寫東西,注意 this.ucDGVChild.ItemClick ,這個是將子節點表格的點選事件向上傳遞

 1  public UCDataGridViewTreeRow()
 2         {
 3             InitializeComponent();
 4             this.ucDGVChild.RowType = this.GetType();
 5             this.ucDGVChild.IsAutoHeight = true;
 6             this.SizeChanged += UCDataGridViewTreeRow_SizeChanged;
 7             this.ucDGVChild.ItemClick += (a, b) =>
 8             {
 9                 if (CellClick != null)
10                 {
11                     CellClick(a, new DataGridViewEventArgs()
12                     {
13                         CellControl = (a as Control),
14                         CellIndex = (a as Control).Tag.ToInt()
15                     });
16                 }
17             };
18 
19         }

實現介面函式BindingCellData,主要處理一下資料繫結後將子節點資料向下傳遞

 1  public void BindingCellData()
 2         {
 3             for (int i = 0; i < Columns.Count; i++)
 4             {
 5                 DataGridViewColumnEntity com = Columns[i];
 6                 var cs = this.panCells.Controls.Find("lbl_" + com.DataField, false);
 7                 if (cs != null && cs.Length > 0)
 8                 {
 9                     var pro = DataSource.GetType().GetProperty(com.DataField);
10                     if (pro != null)
11                     {
12                         var value = pro.GetValue(DataSource, null);
13                         if (com.Format != null)
14                         {
15                             cs[0].Text = com.Format(value);
16                         }
17                         else
18                         {
19                             cs[0].Text = value.ToStringExt();
20                         }
21                     }
22                 }
23             }
24             panLeft.Tag = 0;
25             var proChildrens = DataSource.GetType().GetProperty("Childrens");
26             if (proChildrens != null)
27             {
28                 var value = proChildrens.GetValue(DataSource, null);
29                 if (value != null)
30                 {
31                     int intSourceCount = 0;
32                     if (value is DataTable)
33                     {
34                         intSourceCount = (value as DataTable).Rows.Count;
35                     }
36                     else if (typeof(IList).IsAssignableFrom(value.GetType()))
37                     {
38                         intSourceCount = (value as IList).Count;
39                     }
40                     if (intSourceCount > 0)
41                     {
42                         panLeft.BackgroundImage = Properties.Resources.caret_right;
43                         panLeft.Enabled = true;
44                         panChildGrid.Tag = value;
45                     }
46                     else
47                     {
48                         panLeft.BackgroundImage = null;
49                         panLeft.Enabled = false;
50                         panChildGrid.Tag = null;
51                     }
52                 }
53                 else
54                 {
55                     panLeft.BackgroundImage = null;
56                     panLeft.Enabled = false;
57                     panChildGrid.Tag = null;
58                 }
59             }
60             else
61             {
62                 panLeft.BackgroundImage = null;
63                 panLeft.Enabled = false;
64                 panChildGrid.Tag = null;
65             }
66         }

實現函式繫結列

 1  public void ReloadCells()
 2         {
 3             try
 4             {
 5                 ControlHelper.FreezeControl(this, true);
 6                 this.panCells.Controls.Clear();
 7                 this.panCells.ColumnStyles.Clear();
 8 
 9                 int intColumnsCount = Columns.Count();
10                 if (Columns != null && intColumnsCount > 0)
11                 {
12                     if (IsShowCheckBox)
13                     {
14                         intColumnsCount++;
15                     }
16                     this.panCells.ColumnCount = intColumnsCount;
17                     for (int i = 0; i < intColumnsCount; i++)
18                     {
19                         Control c = null;
20                         if (i == 0 && IsShowCheckBox)
21                         {
22                             this.panCells.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(SizeType.Absolute, 30F));
23 
24                             UCCheckBox box = new UCCheckBox();
25                             box.Name = "check";
26                             box.TextValue = "";
27                             box.Size = new Size(30, 30);
28                             box.Dock = DockStyle.Fill;
29                             box.CheckedChangeEvent += (a, b) =>
30                             {
31                                 IsChecked = box.Checked;
32                                 this.ucDGVChild.Rows.ForEach(p => p.IsChecked = box.Checked);
33                                 if (CheckBoxChangeEvent != null)
34                                 {
35                                     CheckBoxChangeEvent(a, new DataGridViewEventArgs()
36                                     {
37                                         CellControl = box,
38                                         CellIndex = 0
39                                     });
40                                 }
41                             };
42                             c = box;
43                         }
44                         else
45                         {
46                             var item = Columns[i - (IsShowCheckBox ? 1 : 0)];
47                             this.panCells.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(item.WidthType, item.Width));
48 
49                             Label lbl = new Label();
50                             lbl.Tag = i - (IsShowCheckBox ? 1 : 0);
51                             lbl.Name = "lbl_" + item.DataField;
52                             lbl.Font = new Font("微軟雅黑", 12);
53                             lbl.ForeColor = Color.Black;
54                             lbl.AutoSize = false;
55                             lbl.Dock = DockStyle.Fill;
56                             lbl.TextAlign = ContentAlignment.MiddleCenter;
57                             lbl.MouseDown += (a, b) =>
58                             {
59                                 Item_MouseDown(a, b);
60                             };
61                             c = lbl;
62                         }
63                         this.panCells.Controls.Add(c, i, 0);
64                     }
65 
66                 }
67             }
68             finally
69             {
70                 ControlHelper.FreezeControl(this, false);
71             }
72         }

當點選展開圖示的時候處理子節點的資料繫結以及高度計算

 1 private void panLeft_MouseDown(object sender, MouseEventArgs e)
 2         {
 3             try
 4             {
 5                 ControlHelper.FreezeControl(this.FindForm(), true);
 6                 if (panLeft.Tag.ToInt() == 0)
 7                 {
 8                     var value = panChildGrid.Tag;
 9                     if (value != null)
10                     {
11                         panLeft.BackgroundImage = Properties.Resources.caret_down;
12                         panLeft.Tag = 1;
13                         int intSourceCount = 0;
14                         if (value is DataTable)
15                         {
16                             intSourceCount = (value as DataTable).Rows.Count;
17                         }
18                         else if (typeof(IList).IsAssignableFrom(value.GetType()))
19                         {
20                             intSourceCount = (value as IList).Count;
21                         }
22                         this.panChildGrid.Height = RowHeight * intSourceCount;
23                         if (panChildGrid.Height > 0)
24                         {
25                             if (value != this.ucDGVChild.DataSource)
26                             {
27                                 this.ucDGVChild.Columns = Columns;
28                                 this.ucDGVChild.RowHeight = RowHeight;
29                                 this.ucDGVChild.HeadPadingLeft = this.panLeft.Width;
30                                 this.ucDGVChild.IsShowCheckBox = IsShowCheckBox;
31                                 this.ucDGVChild.DataSource = value;
32                                 this.ucDGVChild.Rows.ForEach(p => p.IsChecked =this.IsChecked);
33                             }
34                         }
35                     }
36 
37                 }
38                 else
39                 {
40                     panLeft.Tag = 0;
41                     panChildGrid.Height = 0;
42                     panLeft.BackgroundImage = Properties.Resources.caret_right;
43                 }
44             }
45             finally
46             {
47                 ControlHelper.FreezeControl(this.FindForm(), false);
48             }
49         }

承載子節點表格的panel 在大小改變的時候,處理父級表格的大小。來防止出現多個滾動條

1   void UCDataGridViewTreeRow_SizeChanged(object sender, EventArgs e)
2         {
3             if (this.Parent.Parent.Parent != null && this.Parent.Parent.Parent.Name == "panChildGrid" && this.panLeft.Tag.ToInt() == 1)
4             {
5                 int intHeight = this.Parent.Parent.Controls[0].Controls.ToArray().Sum(p => p.Height);
6                 if (this.Parent.Parent.Parent.Height != intHeight)
7                     this.Parent.Parent.Parent.Height = intHeight;
8             }
9         }

完整程式碼

  1 using System;
  2 using System.Collections.Generic;
  3 using System.ComponentModel;
  4 using System.Drawing;
  5 using System.Data;
  6 using System.Linq;
  7 using System.Text;
  8 using System.Windows.Forms;
  9 using System.Collections;
 10 
 11 namespace HZH_Controls.Controls
 12 {
 13     [ToolboxItem(false)]
 14     public partial class UCDataGridViewTreeRow : UserControl, IDataGridViewRow
 15     {
 16         #region 屬性
 17         public event DataGridViewEventHandler CheckBoxChangeEvent;
 18 
 19         public event DataGridViewEventHandler CellClick;
 20 
 21         public event DataGridViewEventHandler SourceChanged;
 22 
 23         public List<DataGridViewColumnEntity> Columns
 24         {
 25             get;
 26             set;
 27         }
 28 
 29         public object DataSource
 30         {
 31             get;
 32             set;
 33         }
 34 
 35         public bool IsShowCheckBox
 36         {
 37             get;
 38             set;
 39         }
 40         private bool m_isChecked;
 41         public bool IsChecked
 42         {
 43             get
 44             {
 45                 return m_isChecked;
 46             }
 47 
 48             set
 49             {
 50                 if (m_isChecked != value)
 51                 {
 52                     m_isChecked = value;
 53                     (this.panCells.Controls.Find("check", false)[0] as UCCheckBox).Checked = value;
 54                 }
 55             }
 56         }
 57 
 58         int m_rowHeight = 40;
 59         public int RowHeight
 60         {
 61             get
 62             {
 63                 return m_rowHeight;
 64             }
 65             set
 66             {
 67                 m_rowHeight = value;
 68                 this.Height = value;
 69             }
 70         }
 71         #endregion
 72 
 73         public UCDataGridViewTreeRow()
 74         {
 75             InitializeComponent();
 76             this.ucDGVChild.RowType = this.GetType();
 77             this.ucDGVChild.IsAutoHeight = true;
 78             this.SizeChanged += UCDataGridViewTreeRow_SizeChanged;
 79             this.ucDGVChild.ItemClick += (a, b) =>
 80             {
 81                 if (CellClick != null)
 82                 {
 83                     CellClick(a, new DataGridViewEventArgs()
 84                     {
 85                         CellControl = (a as Control),
 86                         CellIndex = (a as Control).Tag.ToInt()
 87                     });
 88                 }
 89             };
 90 
 91         }
 92 
 93         void UCDataGridViewTreeRow_SizeChanged(object sender, EventArgs e)
 94         {
 95             if (this.Parent.Parent.Parent != null && this.Parent.Parent.Parent.Name == "panChildGrid" && this.panLeft.Tag.ToInt() == 1)
 96             {
 97                 int intHeight = this.Parent.Parent.Controls[0].Controls.ToArray().Sum(p => p.Height);
 98                 if (this.Parent.Parent.Parent.Height != intHeight)
 99                     this.Parent.Parent.Parent.Height = intHeight;
100             }
101         }
102 
103 
104         public void BindingCellData()
105         {
106             for (int i = 0; i < Columns.Count; i++)
107             {
108                 DataGridViewColumnEntity com = Columns[i];
109                 var cs = this.panCells.Controls.Find("lbl_" + com.DataField, false);
110                 if (cs != null && cs.Length > 0)
111                 {
112                     var pro = DataSource.GetType().GetProperty(com.DataField);
113                     if (pro != null)
114                     {
115                         var value = pro.GetValue(DataSource, null);
116                         if (com.Format != null)
117                         {
118                             cs[0].Text = com.Format(value);
119                         }
120                         else
121                         {
122                             cs[0].Text = value.ToStringExt();
123                         }
124                     }
125                 }
126             }
127             panLeft.Tag = 0;
128             var proChildrens = DataSource.GetType().GetProperty("Childrens");
129             if (proChildrens != null)
130             {
131                 var value = proChildrens.GetValue(DataSource, null);
132                 if (value != null)
133                 {
134                     int intSourceCount = 0;
135                     if (value is DataTable)
136                     {
137                         intSourceCount = (value as DataTable).Rows.Count;
138                     }
139                     else if (typeof(IList).IsAssignableFrom(value.GetType()))
140                     {
141                         intSourceCount = (value as IList).Count;
142                     }
143                     if (intSourceCount > 0)
144                     {
145                         panLeft.BackgroundImage = Properties.Resources.caret_right;
146                         panLeft.Enabled = true;
147                         panChildGrid.Tag = value;
148                     }
149                     else
150                     {
151                         panLeft.BackgroundImage = null;
152                         panLeft.Enabled = false;
153                         panChildGrid.Tag = null;
154                     }
155                 }
156                 else
157                 {
158                     panLeft.BackgroundImage = null;
159                     panLeft.Enabled = false;
160                     panChildGrid.Tag = null;
161                 }
162             }
163             else
164             {
165                 panLeft.BackgroundImage = null;
166                 panLeft.Enabled = false;
167                 panChildGrid.Tag = null;
168             }
169         }
170 
171         void Item_MouseDown(object sender, MouseEventArgs e)
172         {
173             if (CellClick != null)
174             {
175                 CellClick(this, new DataGridViewEventArgs()
176                 {
177                     CellControl = this,
178                     CellIndex = (sender as Control).Tag.ToInt()
179                 });
180             }
181         }
182 
183         public void SetSelect(bool blnSelected)
184         {
185             if (blnSelected)
186             {
187                 this.panMain.BackColor = Color.FromArgb(255, 247, 245);
188             }
189             else
190             {
191                 this.panMain.BackColor = Color.Transparent;
192             }
193         }
194 
195         public void ReloadCells()
196         {
197             try
198             {
199                 ControlHelper.FreezeControl(this, true);
200                 this.panCells.Controls.Clear();
201                 this.panCells.ColumnStyles.Clear();
202 
203                 int intColumnsCount = Columns.Count();
204                 if (Columns != null && intColumnsCount > 0)
205                 {
206                     if (IsShowCheckBox)
207                     {
208                         intColumnsCount++;
209                     }
210                     this.panCells.ColumnCount = intColumnsCount;
211                     for (int i = 0; i < intColumnsCount; i++)
212                     {
213                         Control c = null;
214                         if (i == 0 && IsShowCheckBox)
215                         {
216                             this.panCells.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(SizeType.Absolute, 30F));
217 
218                             UCCheckBox box = new UCCheckBox();
219                             box.Name = "check";
220                             box.TextValue = "";
221                             box.Size = new Size(30, 30);
222                             box.Dock = DockStyle.Fill;
223                             box.CheckedChangeEvent += (a, b) =>
224                             {
225                                 IsChecked = box.Checked;
226                                 this.ucDGVChild.Rows.ForEach(p => p.IsChecked = box.Checked);
227                                 if (CheckBoxChangeEvent != null)
228                                 {
229                                     CheckBoxChangeEvent(a, new DataGridViewEventArgs()
230                                     {
231                                         CellControl = box,
232                                         CellIndex = 0
233                                     });
234                                 }
235                             };
236                             c = box;
237                         }
238                         else
239                         {
240                             var item = Columns[i - (IsShowCheckBox ? 1 : 0)];
241                             this.panCells.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(item.WidthType, item.Width));
242 
243                             Label lbl = new Label();
244                             lbl.Tag = i - (IsShowCheckBox ? 1 : 0);
245                             lbl.Name = "lbl_" + item.DataField;
246                             lbl.Font = new Font("微軟雅黑", 12);
247                             lbl.ForeColor = Color.Black;
248                             lbl.AutoSize = false;
249                             lbl.Dock = DockStyle.Fill;
250                             lbl.TextAlign = ContentAlignment.MiddleCenter;
251                             lbl.MouseDown += (a, b) =>
252                             {
253                                 Item_MouseDown(a, b);
254                             };
255                             c = lbl;
256                         }
257                         this.panCells.Controls.Add(c, i, 0);
258                     }
259 
260                 }
261             }
262             finally
263             {
264                 ControlHelper.FreezeControl(this, false);
265             }
266         }
267 
268         private void panChildGrid_SizeChanged(object sender, EventArgs e)
269         {
270             int intHeight = RowHeight + panChildGrid.Height;
271             if (panChildGrid.Height != 0)
272                 this.ucDGVChild.Height = panChildGrid.Height;
273             if (this.Height != intHeight)
274                 this.Height = intHeight;
275         }
276 
277         private void panLeft_MouseDown(object sender, MouseEventArgs e)
278         {
279             try
280             {
281                 ControlHelper.FreezeControl(this.FindForm(), true);
282                 if (panLeft.Tag.ToInt() == 0)
283                 {
284                     var value = panChildGrid.Tag;
285                     if (value != null)
286                     {
287                         panLeft.BackgroundImage = Properties.Resources.caret_down;
288                         panLeft.Tag = 1;
289                         int intSourceCount = 0;
290                         if (value is DataTable)
291                         {
292                             intSourceCount = (value as DataTable).Rows.Count;
293                         }
294                         else if (typeof(IList).IsAssignableFrom(value.GetType()))
295                         {
296                             intSourceCount = (value as IList).Count;
297                         }
298                         this.panChildGrid.Height = RowHeight * intSourceCount;
299                         if (panChildGrid.Height > 0)
300                         {
301                             if (value != this.ucDGVChild.DataSource)
302                             {
303                                 this.ucDGVChild.Columns = Columns;
304                                 this.ucDGVChild.RowHeight = RowHeight;
305                                 this.ucDGVChild.HeadPadingLeft = this.panLeft.Width;
306                                 this.ucDGVChild.IsShowCheckBox = IsShowCheckBox;
307                                 this.ucDGVChild.DataSource = value;
308                                 this.ucDGVChild.Rows.ForEach(p => p.IsChecked =this.IsChecked);
309                             }
310                         }
311                     }
312 
313                 }
314                 else
315                 {
316                     panLeft.Tag = 0;
317                     panChildGrid.Height = 0;
318                     panLeft.BackgroundImage = Properties.Resources.caret_right;
319                 }
320             }
321             finally
322             {
323                 ControlHelper.FreezeControl(this.FindForm(), false);
324             }
325         }
326 
327         private void ucDGVChild_SizeChanged(object sender, EventArgs e)
328         {
329 
330         }
331     }
332 }
View Code
  1 namespace HZH_Controls.Controls
  2 {
  3     partial class UCDataGridViewTreeRow
  4     {
  5         /// <summary> 
  6         /// 必需的設計器變數。
  7         /// </summary>
  8         private System.ComponentModel.IContainer components = null;
  9 
 10         /// <summary> 
 11         /// 清理所有正在使用的資源。
 12         /// </summary>
 13         /// <param name="disposing">如果應釋放託管資源,為 true;否則為 false。</param>
 14         protected override void Dispose(bool disposing)
 15         {
 16             if (disposing && (components != null))
 17             {
 18                 components.Dispose();
 19             }
 20             base.Dispose(disposing);
 21         }
 22 
 23         #region 元件設計器生成的程式碼
 24 
 25         /// <summary> 
 26         /// 設計器支援所需的方法 - 不要
 27         /// 使用程式碼編輯器修改此方法的內容。
 28         /// </summary>
 29         private void InitializeComponent()
 30         {
 31             this.panCells = new System.Windows.Forms.TableLayoutPanel();
 32             this.panLeft = new System.Windows.Forms.Panel();
 33             this.panChildGrid = new System.Windows.Forms.Panel();
 34             this.panChildLeft = new System.Windows.Forms.Panel();
 35             this.panMain = new System.Windows.Forms.Panel();
 36             this.ucSplitLine_H1 = new HZH_Controls.Controls.UCSplitLine_H();
 37             this.ucDGVChild = new HZH_Controls.Controls.UCDataGridView();
 38             this.ucSplitLine_V1 = new HZH_Controls.Controls.UCSplitLine_V();
 39             this.panChildGrid.SuspendLayout();
 40             this.panMain.SuspendLayout();
 41             this.SuspendLayout();
 42             // 
 43             // panCells
 44             // 
 45             this.panCells.ColumnCount = 1;
 46             this.panCells.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 100F));
 47             this.panCells.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 20F));
 48             this.panCells.Dock = System.Windows.Forms.DockStyle.Fill;
 49             this.panCells.Location = new System.Drawing.Point(24, 0);
 50             this.panCells.Name = "panCells";
 51             this.panCells.RowCount = 1;
 52             this.panCells.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 100F));
 53             this.panCells.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 55F));
 54             this.panCells.Size = new System.Drawing.Size(637, 64);
 55             this.panCells.TabIndex = 2;
 56             // 
 57             // panLeft
 58             // 
 59             this.panLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Center;
 60             this.panLeft.Dock = System.Windows.Forms.DockStyle.Left;
 61             this.panLeft.Location = new System.Drawing.Point(0, 0);
 62             this.panLeft.Name = "panLeft";
 63             this.panLeft.Size = new System.Drawing.Size(24, 64);
 64             this.panLeft.TabIndex = 0;
 65             this.panLeft.Tag = "0";
 66             this.panLeft.MouseDown += new System.Windows.Forms.MouseEventHandler(this.panLeft_MouseDown);
 67             // 
 68             // panChildGrid
 69             // 
 70             this.panChildGrid.Controls.Add(this.ucDGVChild);
 71             this.panChildGrid.Controls.Add(this.ucSplitLine_V1);
 72             this.panChildGrid.Controls.Add(this.panChildLeft);
 73             this.panChildGrid.Dock = System.Windows.Forms.DockStyle.Bottom;
 74             this.panChildGrid.Location = new System.Drawing.Point(0, 65);
 75             this.panChildGrid.Name = "panChildGrid";
 76             this.panChildGrid.Size = new System.Drawing.Size(661, 0);
 77             this.panChildGrid.TabIndex = 0;
 78             this.panChildGrid.SizeChanged += new System.EventHandler(this.panChildGrid_SizeChanged);
 79             // 
 80             // panChildLeft
 81             // 
 82             this.panChildLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Center;
 83             this.panChildLeft.Dock = System.Windows.Forms.DockStyle.Left;
 84             this.panChildLeft.Location = new System.Drawing.Point(0, 0);
 85             this.panChildLeft.Name = "panChildLeft";
 86             this.panChildLeft.Size = new System.Drawing.Size(24, 0);
 87             this.panChildLeft.TabIndex = 1;
 88             this.panChildLeft.Tag = "0";
 89             // 
 90             // panMain
 91             // 
 92             this.panMain.Controls.Add(this.panCells);
 93             this.panMain.Controls.Add(this.panLeft);
 94             this.panMain.Dock = System.Windows.Forms.DockStyle.Fill;
 95             this.panMain.Location = new System.Drawing.Point(0, 0);
 96             this.panMain.Name = "panMain";
 97             this.panMain.Size = new System.Drawing.Size(661, 64);
 98             this.panMain.TabIndex = 0;
 99             // 
100             // ucSplitLine_H1
101             // 
102             this.ucSplitLine_H1.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(232)))), ((int)(((byte)(232)))), ((int)(((byte)(232)))));
103             this.ucSplitLine_H1.Dock = System.Windows.Forms.DockStyle.Bottom;
104             this.ucSplitLine_H1.Location = new System.Drawing.Point(0, 64);
105             this.ucSplitLine_H1.Name = "ucSplitLine_H1";
106             this.ucSplitLine_H1.Size = new System.Drawing.Size(661, 1);
107             this.ucSplitLine_H1.TabIndex = 1;
108             this.ucSplitLine_H1.TabStop = false;
109             // 
110             // ucDGVChild
111             // 
112             this.ucDGVChild.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 
113             | System.Windows.Forms.AnchorStyles.Right)));
114             this.ucDGVChild.BackColor = System.Drawing.Color.White;
115             this.ucDGVChild.HeadFont = new System.Drawing.Font("微軟雅黑", 12F);
116             this.ucDGVChild.HeadHeight = 40;
117             this.ucDGVChild.HeadPadingLeft = 0;
118             this.ucDGVChild.HeadTextColor = System.Drawing.Color.Black;
119             this.ucDGVChild.IsAutoHeight = false;
120             this.ucDGVChild.IsShowCheckBox = false;
121             this.ucDGVChild.IsShowHead = false;
122             this.ucDGVChild.Location = new System.Drawing.Point(25, 0);
123             this.ucDGVChild.Name = "ucDGVChild";
124             this.ucDGVChild.Page = null;
125             this.ucDGVChild.RowHeight = 40;
126             this.ucDGVChild.RowType = typeof(HZH_Controls.Controls.UCDataGridViewRow);
127             this.ucDGVChild.Size = new System.Drawing.Size(636, 100);
128             this.ucDGVChild.TabIndex = 0;
129             this.ucDGVChild.SizeChanged += new System.EventHandler(this.ucDGVChild_SizeChanged);
130             // 
131             // ucSplitLine_V1
132             // 
133             this.ucSplitLine_V1.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(232)))), ((int)(((byte)(232)))), ((int)(((byte)(232)))));
134             this.ucSplitLine_V1.Dock = System.Windows.Forms.DockStyle.Left;
135             this.ucSplitLine_V1.Location = new System.Drawing.Point(24, 0);
136             this.ucSplitLine_V1.Name = "ucSplitLine_V1";
137             this.ucSplitLine_V1.Size = new System.Drawing.Size(1, 0);
138             this.ucSplitLine_V1.TabIndex = 0;
139             this.ucSplitLine_V1.TabStop = false;
140             // 
141             // UCDataGridViewTreeRow
142             // 
143             this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.None;
144             this.BackColor = System.Drawing.Color.White;
145             this.Controls.Add(this.panMain);
146             this.Controls.Add(this.ucSplitLine_H1);
147             this.Controls.Add(this.panChildGrid);
148             this.Name = "UCDataGridViewTreeRow";
149             this.Size = new System.Drawing.Size(661, 65);
150             this.panChildGrid.ResumeLayout(false);
151             this.panMain.ResumeLayout(false);
152             this.ResumeLayout(false);
153 
154         }
155 
156         #endregion
157 
158         private System.Windows.Forms.TableLayoutPanel panCells;
159         private UCSplitLine_H ucSplitLine_H1;
160         private System.Windows.Forms.Panel panLeft;
161         private System.Windows.Forms.Panel panChildGrid;
162         private UCDataGridView ucDGVChild;
163         private System.Windows.Forms.Panel panChildLeft;
164         private System.Windows.Forms.Panel panMain;
165         private UCSplitLine_V ucSplitLine_V1;
166     }
167 }
View Code

最後的話

如果你喜歡的話,請到 https://gitee.com/kwwwvagaa/net_winform_custom_control 點個星