QQ登录

只需要一步,快速开始

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

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

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

823

主题

3

听众

4048

积分

我的地盘我做主

该用户从未签到

发帖功臣 元老勋章

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

) A$ D" a8 t5 c! l9 t一. 3 c$ z s/ {( _+ w0 p aAnsiString nameString("TButton");- i: @; L" j: d7 _0 x TButton * button; & W) O& I9 M f9 i% U7 C2 kfor(int i=0; i < ComponentCount; i++) ! e9 L4 [5 H$ y7 f0 t( A{4 O! T j9 e' f //Check to see if the component is a TButton6 l" U" a3 d# B; f if (Components->ClassNameIs(nameString))# Q5 J; W( R& N9 t" k8 Z+ b, g3 ^ {6 m( j: P q6 S5 v5 e( ` //cast the component to a TButton *% o: {& u% O: f* F4 d button = (TButton *)Components; ! f- R% x4 f/ I4 p; x/ U& }button->Font->Name = "Courier"; % m7 ?2 {8 h, a; Z3 }# d- ?7 q; n ......

2 m, X+ P6 x7 q. M z

( X' m! r, f6 F5 G: p二.2 o+ u7 `* K; V( T. w 我想动态创建和静态创建都没有太大区别,只要它属于你的MainForm。( new TButton(this) ). 5 c9 `, i1 j V2 i用一个需循环. R+ h9 p" {, V" E TButton* button; 2 W5 ?, R6 N7 F! pfor(int i=0;i<MainForm->ComponentCount;i++){) r* j* l- e& b. Q if((button= dynamic_cast<TButton*>(MainForm->Components)) != NULL )3 V- j% [. m" P' x, z( s button->Caption="Button";5 Q. {$ [3 p0 V$ g2 X+ P }0 T# X% ~/ Z3 f% n! N, F

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-6-12 21:30 , Processed in 0.413201 second(s), 54 queries .

回顶部