/**/
/// <summary>
/// 广度优先
/// </summary>
/// <param name="control"></param>
private void FindSelecedControl1(Control control)
{
Queue que = new Queue();
Control ctlCurrent;
que.Enqueue(control);
while(que.Count != 0)
{
ctlCurrent = (Control)que.Dequeue(); // 最先加入队列的节点出列
if(true) // 访问之
{
if(ctlCurrent.ID != null)
aList.Add(ctlCurrent.ID);
}
for(int i = 0; i < ctlCurrent.Controls.Count; i++) // 把ctlCurrent的子节点入列
{
que.Enqueue(ctlCurrent.Controls[i]);
}
}
}
/// 广度优先
/// </summary>
/// <param name="control"></param>
private void FindSelecedControl1(Control control)
{
Queue que = new Queue();
Control ctlCurrent;
que.Enqueue(control);
while(que.Count != 0)
{
ctlCurrent = (Control)que.Dequeue(); // 最先加入队列的节点出列
if(true) // 访问之
{
if(ctlCurrent.ID != null)
aList.Add(ctlCurrent.ID);
}
for(int i = 0; i < ctlCurrent.Controls.Count; i++) // 把ctlCurrent的子节点入列
{
que.Enqueue(ctlCurrent.Controls[i]);
}
}
}
/**/
/// <summary>
/// 深度优先
///
/// </summary>
/// <param name="control"></param>
private void FindSelecedControl(Control control)
{
Stack stk = new Stack();
Control ctlCurrent = control; // 当前访问的控件
Control ctlParent = null; // 父控件
int index = 0; // 当前控件是父控件的第i个子控件
do
{
if(true) // 判断当前控件(ctrCurrent)是不是要找的
{
if(ctlCurrent.ID != null)
aList.Add(ctlCurrent.ID);
}
if(ctlCurrent.Controls.Count != 0) // 访问完当前控件,优先访问子控件
{
stk.Push(index); //发现子,current = parent.controls[index].将index推入棧
index = 0;
ctlParent = ctlCurrent;
ctlCurrent = ctlCurrent.Controls[0];
}
else if(ctlParent != null && index + 1 < ctlParent.Controls.Count) // 存在下一个兄弟控件
{
ctlCurrent = ctlParent.Controls[++index];
}
else // 没有子控件和下一个兄弟控件
{
while(true)
{
if(ctlParent == null || ctlParent.Equals(control))
{
ctlCurrent = control;
break;
}
ctlCurrent = ctlParent;
ctlParent = ctlCurrent.Parent;
index = (int)stk.Pop();
if(ctlParent != null && index + 1 < ctlParent.Controls.Count)
{
ctlCurrent = ctlParent.Controls[++index];
break;
}
}
}
}while(!ctlCurrent.Equals(control));
}
/// 深度优先
///
/// </summary>
/// <param name="control"></param>
private void FindSelecedControl(Control control)
{
Stack stk = new Stack();
Control ctlCurrent = control; // 当前访问的控件
Control ctlParent = null; // 父控件
int index = 0; // 当前控件是父控件的第i个子控件
do
{
if(true) // 判断当前控件(ctrCurrent)是不是要找的
{
if(ctlCurrent.ID != null)
aList.Add(ctlCurrent.ID);
}
if(ctlCurrent.Controls.Count != 0) // 访问完当前控件,优先访问子控件
{
stk.Push(index); //发现子,current = parent.controls[index].将index推入棧
index = 0;
ctlParent = ctlCurrent;
ctlCurrent = ctlCurrent.Controls[0];
}
else if(ctlParent != null && index + 1 < ctlParent.Controls.Count) // 存在下一个兄弟控件
{
ctlCurrent = ctlParent.Controls[++index];
}
else // 没有子控件和下一个兄弟控件
{
while(true)
{
if(ctlParent == null || ctlParent.Equals(control))
{
ctlCurrent = control;
break;
}
ctlCurrent = ctlParent;
ctlParent = ctlCurrent.Parent;
index = (int)stk.Pop();
if(ctlParent != null && index + 1 < ctlParent.Controls.Count)
{
ctlCurrent = ctlParent.Controls[++index];
break;
}
}
}
}while(!ctlCurrent.Equals(control));
}