我可以使用C#和amp;在窗口中找出动态添加的控件吗?网? [英] can i find out dynamic added control in window using C# & net?

查看:64
本文介绍了我可以使用C#和amp;在窗口中找出动态添加的控件吗?网?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

想使用C#和net在窗口中查找动态添加的控件.我可以找到它还是不找到.

want to find out dynamic added control in window using C# & net.Can i find it or not.

推荐答案

逻辑上的事情是,不要丢失它,即在不保留对它的引用的情况下不要添加控件.但是,可以根据需要递归遍历控件集合并搜索控件.
The logical thing to do, is to not lose it, that is, to not add a control without keeping a reference to it. However, you can iterate recursively through your controls collection and search for the control, if you need to.


您尚未设置文本框的名称.查找方法基于控件的名称"属性进行搜索.设置文本框的Name属性,它将起作用.

更好的方法是使TextBox对象成为类级别的对象,这样您就不必一次又一次地搜索它.
You haven''t set the name for the textbox. Find method searches based on the Name property of the controls. Set the Name property for the textbox and it will work.

A better way to do this would be make that TextBox object a class level object so that you don''t need to search for it again and again.


您忘记设置name属性.将其设置为
txnew.Name ="txnew";

然后它将为您工作.
You has forget to set name property. set it like
txnew.Name="txnew";

Then it will work for you.


这篇关于我可以使用C#和amp;在窗口中找出动态添加的控件吗?网?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆