下面的示例演示了如何递归遍历特定面板中的子面板。 IterateChildPanels 方法为特定面板的最末子面板 (在顺序上没有包含任何子面板的子面板) 调用了 DoSomeOperation 方法。

C#CopyCode image复制代码
using DevExpress.XtraBars.Docking;
// ...
void DoSomeOperation(DockPanel panel) {
   //...
}

void IterateChildPanels(DockPanel parentPanel) {
   if(parentPanel == null) return;
   for(int i = 0; i < parentPanel.Count; i++) {
      DockPanel childPanel = parentPanel[i];
      if(childPanel.Count == 0)
         DoSomeOperation(childPanel);
      else
         IterateChildPanels(childPanel);
   }
}

Visual BasicCopyCode image复制代码
Imports DevExpress.XtraBars.Docking
' ...
Sub DoSomeOperation(ByVal panel As DockPanel)
   '...
End Sub

Sub IterateChildPanels(ByVal parentPanel As DockPanel)
   If parentPanel Is Nothing Then Return
   Dim i As Integer
   For i = 0 To parentPanel.Count - 1
      Dim childPanel As DockPanel = parentPanel(i)
      If childPanel.Count = 0 Then
         DoSomeOperation(childPanel)
      Else
         IterateChildPanels(childPanel)
      End If
   Next
End Sub