韩冰 发表于 2005-1-26 12:28

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

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