C# tabcontrol和tabpage问题
if (tabpage1.Parent == null) tabpage1.Parent = tabcontrol;
if (tabpage2.Parent == null) tabpage2.Parent = tabcontrol;
if (tabpage3.Parent == null) tabpage3.Parent = tabcontrol;
if (tabpage4.Parent == null) tabpage4.Parent = tabcontrol;
............
我有tabpage十几个,想实现的效果就是上述代码写的,请问怎么用循环或者更简洁的方法呢?
------解决方案--------------------
C# code
for(int i=0;i<count;i++)
{
object o = this.GetType().GetField("tabpage" +i, System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic).GetValue(this);
TabPage tp=(TabPage)o;
if (tp.Parent == null) tp.Parent = tabcontrol;
}