QQ登录

只需要一步,快速开始

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

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

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

823

主题

3

听众

4048

积分

我的地盘我做主

该用户从未签到

发帖功臣 元老勋章

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

9 J7 s7 E' }2 x一. & U& T& c) E) C' aAnsiString nameString("TButton"); 0 A ]/ U; A; Z0 N" E. uTButton * button;. [# S' {% W0 {: g2 S! { for(int i=0; i < ComponentCount; i++)0 z( Q' t9 a3 ~' j, | {0 V' c8 l! @8 G& w1 A6 G //Check to see if the component is a TButton . h# ^7 d3 |; w( [, lif (Components->ClassNameIs(nameString))$ U( A: p) Q# y+ y- S { , n3 V" x* U. t$ E6 b4 m//cast the component to a TButton * : H4 |! `' a% c* gbutton = (TButton *)Components;' s6 q/ l3 l: _" w' N" a ^- n button->Font->Name = "Courier"; & I4 I$ O) ~4 u- r9 ^ ......

$ ^& ]: T) C n/ `8 y6 S- y! h

2 ^' ^# {2 C+ @" i% e 二. ( Y" i R$ O! [1 o: B- |2 C我想动态创建和静态创建都没有太大区别,只要它属于你的MainForm。( new TButton(this) ).! I9 w" l1 w- `' K 用一个需循环 / S& ^* Y) F8 j7 dTButton* button; 8 `! t, U/ W) T+ i- {for(int i=0;i<MainForm->ComponentCount;i++){5 Q& U3 \8 c+ c if((button= dynamic_cast<TButton*>(MainForm->Components)) != NULL )* e' Q/ {; T/ F5 _8 I0 l button->Caption="Button";; ]5 P6 J( z ~9 a) I: Z }8 s! p* B Q2 L) J

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

fastpost qq
收缩
  • 电话咨询

  • 04714969085

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

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

蒙公网安备 15010502000194号

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

GMT+8, 2026-12-4 03:45 , Processed in 1.758514 second(s), 52 queries .

回顶部