WinForm中如何将字符串转化为控件名称?

xp1056 2009-06-16 05:17:15
如题:
WinForm中如何将字符串转化为控件名称?
...全文
1070 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
xp1056 2009-06-16
  • 打赏
  • 举报
回复 1
[Quote=引用 5 楼 smntbk 的回复:]
C# codeControl col = this.GroupBox1.Controls.Find("控件名", true)[0];
Button btn = col as Button;//转为Button
[/Quote]
谢谢这个可以~~
feiyun0112 2009-06-16
  • 打赏
  • 举报
回复
Control c=this.Controls.Find("controlname",true)[0];


*****************************************************************************
欢迎使用CSDN论坛专用阅读器 : CSDN Reader(附全部源代码)

http://feiyun0112.cnblogs.com/
xp1056 2009-06-16
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 fengjian_428 的回复:]
控件的名称不是本来就是string吗? 为什么要转
[/Quote]
我要动态的改变一组Label的Text值 根据条件决定得出一组字符串,
这些字符串表示的就是label的名称,要将这些字符串转变为控件名,然后给控件的text赋值。
Jim@luckeeinc.com 2009-06-16
  • 打赏
  • 举报
回复
估计lz的意思是要根据控件的name来获得这个控件吧
按照楼上的方法就可以了
smntbk 2009-06-16
  • 打赏
  • 举报
回复
Control col = this.GroupBox1.Controls.Find("控件名", true)[0];
Button btn = col as Button;//转为Button
fengjian_428 2009-06-16
  • 打赏
  • 举报
回复
控件的名称不是本来就是string吗? 为什么要转
让爱延续 2009-06-16
  • 打赏
  • 举报
回复

string str="strName";
Button btn=new Button();
btn.Name=str;


这只是举个例子,只要将string赋值于某个控件实例的Name属性就可以了。
xp1056 2009-06-16
  • 打赏
  • 举报
回复
我是将一个字符串转化为控件名称,控件名是既存的控件的名称。。。
ffffssd 2009-06-16
  • 打赏
  • 举报
回复
强制转化

Button btnSend=new Button();
btnSend=(Button)sender;

这个是我用于动态创建的控件中!

110,566

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧