QQ登录

只需要一步,快速开始

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

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

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

823

主题

3

听众

4048

积分

我的地盘我做主

该用户从未签到

发帖功臣 元老勋章

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

. G( d: S8 |* c5 Y: }! m 一.; j1 o# A( {& }5 k: F1 N) t% ^2 \# q4 q AnsiString nameString("TButton");* V$ S# x! F' v TButton * button;0 E/ j5 U+ k7 [2 i( d for(int i=0; i < ComponentCount; i++) ; {* Y4 y& S. m# _{/ a, h w( S2 f //Check to see if the component is a TButton . w2 s& b" @) K4 q$ mif (Components->ClassNameIs(nameString)) + i' O* H6 s6 M6 F7 Y+ e0 q{ 4 W: k* B# h% C! o2 E//cast the component to a TButton *. n7 W; X- Q# t% U4 P6 P1 ^ | button = (TButton *)Components;; m5 E3 W4 q: d6 C8 c) P button->Font->Name = "Courier"; " ?. x) U8 I K. c6 p0 I2 ^ ......

9 |7 ?$ q0 F* m

8 v& ^+ W$ b" V2 R二.! u. P9 ~: ?1 Y. s, b 我想动态创建和静态创建都没有太大区别,只要它属于你的MainForm。( new TButton(this) ). $ O3 K0 X. g$ V" A( I8 c7 ~用一个需循环 2 X {! q8 ^" w+ MTButton* button; 8 W1 D9 H9 L6 Y: Q3 }6 Z$ rfor(int i=0;i<MainForm->ComponentCount;i++){ 9 v5 f! H" D( `! hif((button= dynamic_cast<TButton*>(MainForm->Components)) != NULL ) " \ f) L1 n" a7 W! Z) R& W button->Caption="Button"; 7 K+ z4 {* s9 L, T8 O n N4 q} 9 y1 S* T, l, Y, x- g @

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 16:27 , Processed in 0.439092 second(s), 52 queries .

回顶部