2007/05/07

運用遞迴深度列舉動態新增控制項

********************
//C#
public List EnumControls(List ctlContainer, Control BaseControl)
{
if (ctlContainer == null)
ctlContainer = new List();
ctlContainer.Add(BaseControl);
foreach (Control ctl in BaseControl.Controls)
ctlContainer = EnumControls(ctlContainer, ctl);
return ctlContainer;
}

'Visual Basic
Public Function EnumControls(ctlContainer As List(Of Control), BaseControl As Control) As List(Of Control)
If ctlContainer Is Nothing Then
ctlContainer = new List(Of Control)()
End If
ctlContainer.Add(BaseControl)
For Each ctl As Control In BaseControl.Controls
ctlContainer = EnumControls(ctlContainer, ctl)
Next ctl
Return ctlContainer;
End Function

********************

參考:微軟MSDN

標籤:

0 Comments:

張貼留言

<< Home