数学建模社区-数学中国

标题: 如何遍历主窗体MainForm中所有的Button控件? [打印本页]

作者: 韩冰    时间: 2005-1-26 12:28
标题: 如何遍历主窗体MainForm中所有的Button控件?

/ z' x7 B$ c6 A, ^, T9 { 一.: a1 z8 G! z) k% { AnsiString nameString("TButton"); - ^" @ G6 l r- [TButton * button; % l8 I. c; l6 j% m8 bfor(int i=0; i < ComponentCount; i++) 3 I% I9 G j5 o/ k. g* l8 U: |{- R. j, `# y( _* A& L //Check to see if the component is a TButton/ d8 s% h; R; E' Z if (Components->ClassNameIs(nameString)) " O& u. u! s h+ {: P/ g+ U{ 1 h8 _& T. H' a6 L//cast the component to a TButton *% S1 }3 U! M) C' L6 r, ~( @ button = (TButton *)Components;7 e' n, W- X- n6 A button->Font->Name = "Courier";, Q2 K. X. Z- @9 V8 I ......

8 W( R+ `* m5 y, ]

+ e( U9 A6 y) K6 i, ^% P" x" ?$ m 二. ( A$ u# B3 i' |# y5 \0 g我想动态创建和静态创建都没有太大区别,只要它属于你的MainForm。( new TButton(this) ). 0 P! e! g# s- s6 e用一个需循环 ' @( _4 [. ]9 G3 hTButton* button;8 ]5 g& s- m2 n! E; \0 M; s3 Q# w for(int i=0;i<MainForm->ComponentCount;i++){ : E2 v) D/ H- cif((button= dynamic_cast<TButton*>(MainForm->Components)) != NULL ) \# |, e+ L" a; h button->Caption="Button";7 k" J) B% \) L% B: y }5 `2 N9 T$ J! _$ X3 i






欢迎光临 数学建模社区-数学中国 (http://www.madio.net/) Powered by Discuz! X2.5