如何遍历主窗体MainForm中所有的Button控件?
<P>一.
AnsiString nameString("TButton");
TButton * button;
for(int i=0; i < ComponentCount; i++)
{
//Check to see if the component is a TButton
if (Components->ClassNameIs(nameString))
{
//cast the component to a TButton *
button = (TButton *)Components;
button->Font->Name = "Courier";
......</P>
<P>
二.
我想动态创建和静态创建都没有太大区别,只要它属于你的MainForm。( new TButton(this) ).
用一个需循环
TButton* button;
for(int i=0;i<MainForm->ComponentCount;i++){
if((button= dynamic_cast<TButton*>(MainForm->Components)) != NULL )
button->Caption="Button";
}
</P>
页:
[1]