WinForm开发中几种找控件的方法

摘要:
=newobj)&&(null!=newobj.GetType().GetInterface(intfType.Name))){aRet.Add(newobj);}}}returnaRet;}

#region 在当前控件集中查找ToolStripButton
private static ToolStripButton FindToolStripButton(Form owner, string controlId)
{
ToolStripButton result;
result = null;
foreach (Control ctl in owner.Controls)
{
if (ctl.GetType() == typeof(System.Windows.Forms.ToolStrip))
{
ToolStrip ts = ctl as ToolStrip;
ToolStripItem[] items = ts.Items.Find(controlId, true);
if (items.Length > 0)
{
result = (ToolStripButton)items[0];
return result;
}
}
}
return result;
}
#endregion

//Form中直接找

Control[] ctls = owner.Controls.Find(dr["ControlName"].ToString(), true);

//Form的Components中找控件

ArrayList myList = owner.GetIntfObjects(typeof(IFindContainer));
for (int i = 0; i < myList.Count; i++)
{

if(myList[i] is DataSet)

{}

}

public ArrayList GetIntfObjects(Type intfType)
{
ArrayList aRet = new ArrayList();

ReflectionPermission reflectionPerm1 = new ReflectionPermission(PermissionState.None);
reflectionPerm1.Flags = ReflectionPermissionFlag.AllFlags;

if (intfType.IsInterface)
{
Type type = this.GetType();
FieldInfo[] myFields = type.GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.DeclaredOnly);
for (int i = 0; i < myFields.Length; i++)
{
object newobj = myFields[i].GetValue(this);
if ((null != newobj) && (null != newobj.GetType().GetInterface(intfType.Name)))
{
aRet.Add(newobj);
}
}
}
return aRet;
}

免责声明:文章转载自《WinForm开发中几种找控件的方法》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇在Mac OSX 10.10 上安装opencv传统软件开发模式下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

Java线程并发中常见的锁--自旋锁 偏向锁

随着互联网的蓬勃发展,越来越多的互联网企业面临着用户量膨胀而带来的并发安全问题。本文着重介绍了在java并发中常见的几种锁机制。 1.偏向锁 偏向锁是JDK1.6提出来的一种锁优化的机制。其核心的思想是,如果程序没有竞争,则取消之前已经取得锁的线程同步操作。也就是说,若某一锁被线程获取后,便进入偏向模式,当线程再次请求这个锁时,就无需再进行相关的同步操作...

关于WinForm中的DataGridView控件显示数据字典的解决方案。

做这部分功能的时候,上网搜索了很多资料,发现很少涉及到这方面的解决方案,找了相关的问题帖子,很多人都叫使用视图去处理,当然,用视图是可以解决这个问题,但是,这么多个表,都用视图去搞,那还得做这么多个视图...........这肯定不科学了。还有如果用视图去做,那么数据实体就与实际的表不一致了,所以,我们需要找到一个解决DataGridView的某个列需要按...

C# WinForm获取当前路径汇总

Winform获取应用程序的当前路径的方法集合,具体如下,值得收藏//获取当前进程的完整路径,包含文件名(进程名)。string str = this.GetType().Assembly.Location;result: X:xxxxxxxxx.exe (.exe文件所在的目录+.exe文件名)//获取新的Process 组件并将其与当前活动的进程关联的...

计算最长英语单词链

计算最长英语单词链的题目为: 大家经常玩成语接龙游戏,我们试一试英语的接龙吧:一个文本文件中有N 个不同的英语单词, 我们能否写一个程序,快速找出最长的能首尾相连的英语单词链,每个单词最多只能用一次。最长的定义是:最多单词数量,和单词中字母的数量无关。 统一输入文件名称:input1.txt, input2.txt 统一输出文件名称:output1.txt...

C# arrayList动态添加对象元素,并取出对象元素的方法

先建一个类,类中有两个变量作为坐标值 publicclassremtbpoint //remtbpoint 类(用来记忆某对象坐标){ privateintrpointline;privateintrpointcol;{get{ returnrpointline; }set{ rpoin...

C#中遍历各类数据集合的方法总结

C#中遍历各类数据集合的方法总结: 1.枚举类型  //遍历枚举类型Sample的各个枚举名称 foreach (string sp in Enum.GetNames(typeof(Sample))) { ary.Add(sp); } //遍历枚举类型Sample的各个枚举值 foreach (string sp in Enum.GetValu...