QQ登录

只需要一步,快速开始

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

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

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

823

主题

3

听众

4048

积分

我的地盘我做主

该用户从未签到

发帖功臣 元老勋章

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

, A3 l' K- g3 p+ k( t一. / ~. ^% A; I! u7 I$ ~( tAnsiString nameString("TButton"); 5 [# e1 m6 g( w" d- g- @9 ^" DTButton * button;& W* o" u* \/ T; m# w for(int i=0; i < ComponentCount; i++) * n9 g" i6 h# r0 z- I+ [, N$ N+ L{0 e8 q0 D, v! a5 X: h! [. D: s6 s //Check to see if the component is a TButton ) Z9 Z3 j8 L. b" Q' \0 a+ Bif (Components->ClassNameIs(nameString)) ; H, A; i6 y4 y$ y" u{ . Q" ~; T2 a0 m" X3 ~1 H: _//cast the component to a TButton *, Y( o- I1 g% `0 z* L' [ button = (TButton *)Components;8 G4 D1 [2 d3 [1 ~& S6 _, x button->Font->Name = "Courier";9 G6 o) K( Q! a2 K' D9 K ......

3 Y$ t( ]0 J& A: Z; j5 Y5 {

. z& t! c( b; L! ]: e1 K3 Z. Q( h二. 3 }0 }! [5 c' @/ D我想动态创建和静态创建都没有太大区别,只要它属于你的MainForm。( new TButton(this) ). 2 @$ B+ b1 c2 a/ B( B i: J& F6 Y用一个需循环0 f' |3 {8 F: Z TButton* button;. G ?- u- F- q8 g& L$ I3 |! m for(int i=0;i<MainForm->ComponentCount;i++){ 0 ]% Z2 I. y0 ?$ {if((button= dynamic_cast<TButton*>(MainForm->Components)) != NULL ) 0 e) \8 ~* H' w6 j7 ^# c button->Caption="Button";- r+ s1 U0 e6 a& i; u( A- t; n8 Q }# W9 d' [' z/ [6 ?

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-10-17 09:03 , Processed in 0.312393 second(s), 52 queries .

回顶部