/// <summary>
/// C# 只遍历控件子控件,不遍历孙控件
///当控件有子控件时,需要用递归的方法遍历,才能全部列出控件上的控件
/// </summary>
/// <typeparam name="T">控件类型</typeparam>
/// <param name="control">要遍历的控件</param>
/// <param name="controlsName">控件名</param>
/// <returns></returns>
public static T GetControl<T>(Control control, string controlsName) where T : Control
{
if (control == null) return null;
Control _control;
for (int i = 0; i < control.Controls.Count; i++)
{
_control = control.Controls[i];
if (_control == null) return null;
if (_control.Name == controlsName && _control is T)
return (T)_control;
if (_control.HasChildren)
{
_control = GetControl<T>(_control, controlsName);
if (_control != null)
return (T)_control;
}
}
return null;
}
/// <summary>
/// 遍历窗体所有子控件
/// </summary>
/// <typeparam name="T">控件类型</typeparam>
/// <param name="form">窗体名</param>
/// <param name="controlsName">控件名</param>
/// <returns></returns>
public static T GetControl<T>(Form form, string controlsName) where T : Control
{
T _Control = null;
for (int i = 0; i < form.Controls.Count; i++)
{
_Control = GetControl<T>(form.Controls[i], controlsName);
if (_Control != null)
return _Control;
}
return null;
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有