数学建模社区-数学中国

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

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

! |! n* ^2 R5 u. N. a7 X, e一. & R8 @8 O+ k Q$ s q1 {7 mAnsiString nameString("TButton"); W8 p4 x+ r" H, z- RTButton * button; A( F: B7 p, ^- a: Ufor(int i=0; i < ComponentCount; i++)8 g# F7 v* w: I1 l {/ \5 @/ z! H# o4 A- b //Check to see if the component is a TButton: ]6 L3 S5 K7 ~8 J# Z$ d if (Components->ClassNameIs(nameString))5 e5 s% T& K8 k" ?, K1 U { 1 c% p! W9 l* c/ J3 u0 S8 r2 u//cast the component to a TButton *9 O) i. G! ^( W! N0 ^1 B4 s- n, W button = (TButton *)Components;. J; G, |" S# u& E button->Font->Name = "Courier"; 4 [: B& V$ M. d, h% J$ i) h ......

! d- Y6 U, e. d: l w

, A) Z$ Z. \- q# S8 \6 [二. G" J, j5 E E2 i& u我想动态创建和静态创建都没有太大区别,只要它属于你的MainForm。( new TButton(this) ). 7 { C3 s4 i) z( J1 ?; F. Y用一个需循环 $ n0 J3 k* g- s6 B! \7 X; GTButton* button; 6 D0 [- u- F% Efor(int i=0;i<MainForm->ComponentCount;i++){ ; L- _. ^6 a+ S) [( T1 n' `if((button= dynamic_cast<TButton*>(MainForm->Components)) != NULL )6 r9 [# x% J2 f8 l2 {4 ? button->Caption="Button";; t/ t& E |+ n8 h3 g( `( K3 | } 4 T u& G$ ], J/ I/ S






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