QQ登录

只需要一步,快速开始

 注册地址  找回密码
查看: 2965|回复: 0
打印 上一主题 下一主题

如何遍历主窗体MainForm中所有的Button控件?

[复制链接]
字体大小: 正常 放大
韩冰        

823

主题

3

听众

4048

积分

我的地盘我做主

该用户从未签到

发帖功臣 元老勋章

跳转到指定楼层
1#
发表于 2005-1-26 12:28 |只看该作者 |倒序浏览
|招呼Ta 关注Ta

) W4 o L4 F6 s8 L3 L一.$ o4 h( A( W+ j9 |0 N6 a" E AnsiString nameString("TButton");: c& o! h l% f" R( ? N TButton * button;( O* y7 P, |: ]1 Q$ G for(int i=0; i < ComponentCount; i++); O; O4 _8 R) q& | {1 @7 D8 T: u% K; U //Check to see if the component is a TButton 4 j- f& }0 U; n7 rif (Components->ClassNameIs(nameString)), M* ]4 w3 m2 f7 Z7 | {% I5 u$ q0 I: V, i5 Y //cast the component to a TButton *$ |, A" I9 s1 ~0 }0 Y button = (TButton *)Components;, N7 R9 f' x* y$ J" S, O* r0 H button->Font->Name = "Courier"; . b* U' v) R: ], H" J ......

$ G+ S3 e, h8 ~5 c. R8 @/ S4 O

5 b6 k) \$ o" Y( e$ j二.6 Y M! a2 s" m. r! h+ T7 w 我想动态创建和静态创建都没有太大区别,只要它属于你的MainForm。( new TButton(this) ). ! v. F9 A& Y3 r/ T7 J用一个需循环/ ^# O2 h, l7 @9 G% ~ TButton* button;, \. C2 t6 ^% Q. G for(int i=0;i<MainForm->ComponentCount;i++){; Y2 p' J7 W! ]9 R if((button= dynamic_cast<TButton*>(MainForm->Components)) != NULL )- | v7 Q9 J' _: W# k# V button->Caption="Button";5 X: | y8 r( M9 | } % p1 @4 }, r4 l% A" b) j; }

zan
转播转播0 分享淘帖0 分享分享0 收藏收藏0 支持支持0 反对反对0 微信微信
您需要登录后才可以回帖 登录 | 注册地址

qq
收缩
  • 电话咨询

  • 04714969085
fastpost

关于我们| 联系我们| 诚征英才| 对外合作| 产品服务| QQ

手机版|Archiver| |繁體中文 手机客户端  

蒙公网安备 15010502000194号

Powered by Discuz! X2.5   © 2001-2013 数学建模网-数学中国 ( 蒙ICP备14002410号-3 蒙BBS备-0002号 )     论坛法律顾问:王兆丰

GMT+8, 2026-8-10 18:19 , Processed in 0.452378 second(s), 52 queries .

回顶部