数学建模社区-数学中国

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

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

. W( G9 E; @3 W0 x一.8 g- `: ~, g; g& f5 K AnsiString nameString("TButton");& M( A) m7 o# A; S0 B TButton * button; 3 n3 [0 w; y% pfor(int i=0; i < ComponentCount; i++), @, a/ m; H' L {* b* d1 R$ _( N //Check to see if the component is a TButton ' b- \& L( d# H' f0 s0 F: dif (Components->ClassNameIs(nameString))5 d7 ]5 Z0 T+ L3 G- M* @( V1 Z% x {# f$ ~6 a6 Y3 e6 Y: @" | //cast the component to a TButton *. n3 T& Y6 Q5 i/ S" a- {$ s button = (TButton *)Components;- V7 W! ?! s S" E button->Font->Name = "Courier"; 1 B: S/ S+ f% {+ ? ......

, {5 f" o4 c; o1 l- M2 b

4 j; U/ ^1 \. [/ ~4 p# y$ B8 b二.8 U- t X1 B7 ]% t 我想动态创建和静态创建都没有太大区别,只要它属于你的MainForm。( new TButton(this) ).4 ~" Z$ d: y, C f 用一个需循环4 U! g& j& R$ V4 t+ [ TButton* button;: x' c5 J6 v p. P for(int i=0;i<MainForm->ComponentCount;i++){ 1 o6 T2 G: s. v4 X" U* Jif((button= dynamic_cast<TButton*>(MainForm->Components)) != NULL ) 2 ]6 u8 V8 z2 D' S button->Caption="Button";4 q8 \* j: p' N m% z5 R& P }. C/ n2 p* s: q- h






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