wxButton *btn[10];
for(size_t i = 0;i != 10;i++)
{
result = text.Mid(i,1);
btn[i] = new wxButton(this,wxID_ANY,result);
r = rand() %128 + 127;
g = rand() %128 + 127;
b = rand() %128 + 127;
btn[i]->SetBackgroundColour(wxColour(r,g,b));
btn[i]->Bind(wxEVT_COMMAND_BUTTON_CLICKED,LayoutWrapSizer::OnButtonClicked,this);
sizer->Add(btn[i],0,wxALL,5);
}
控件数组与以下的代码等价
for(size_t i = 0;i != text.Len();i++)
{
result = text.Mid(i,1);
wxButton *btn = new wxButton(this,wxID_ANY,result);
r = rand() %128 + 127;
g = rand() %128 + 127;
b = rand() %128 + 127;
btn->SetBackgroundColour(wxColour(r,g,b));
btn->Bind(wxEVT_COMMAND_BUTTON_CLICKED,LayoutWrapSizer::OnButtonClicked,this);
sizer->Add(btn,0,wxALL,5);
}