alle Buttons im Formular in Schleife durchlaufen
-
Hallo wie kann ich alle Buttons mit einer Schleife ansprechen?
for each(Buttons ^but in ?????)
Gruß
-
Die Buttons sind auch Controls und desshalb in dem entsprechenden Property der Form zu finden.
http://msdn.microsoft.com/de-de/library/system.windows.forms.control.controls.aspxAllerdings musst Du noch testen ob es sich bei dem entsprechenden Control wirklich um ein Button handelt.
Simon
-
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) { FindAllButtons(this); } void FindAllButtons(Control^ root) { if (root == nullptr) return; for each(Control^ ctrl in root->Controls) { auto btn = dynamic_cast<Button^>(ctrl); if (btn != nullptr) { System::Diagnostics::Debug::WriteLine("Button gefunden"); } else { FindAllButtons(ctrl); } } }