Hello. Is it possible somehow

button1->visible= true; button2->visible= true button3->visible= true; 

Write to for? It doesn't work

 for (int i=1; i=3; i++) { button_i->visible=true; } 
  • @ GALIAF95, Do not forget to accept answers to your questions. If you are given an exhaustive answer, mark it as correct (click on the check mark next to the selected answer). - Yura Ivanov

1 answer 1

If you create buttons in run-time, you can shove them into a container and refer to the index. Also the form must have a container.

  • can you please explain more simply, just recently started to study vis c ++ - GALIAF95
  • Yes, everything is simple. Only the specifics of VS I do not know. I will explain with the example of the forgotten borland builder or delphi. If the buttons are created by code, then to access them by index, you can do this: ObjectList buttons = new ObjectList (); I’m not sure about the container - I don’t remember exactly what it is, but I think the meaning is clear. If you create an interface by pulling elements onto a form, then the form also has some kind of container, but all the elements of the form are stored there, so in order to access an element, you first need to check if that element is, and then do with it something. - RomanoO
  • The simplest container is an array of pointers. It is possible and container classes, as advised @Romanoo, only in C ++ this way after the appearance of the template, and especially stl is not very popular. - alexlz
  • You can't do something simpler, instead of button1 write buttoni in a loop? Or another question, how to create a run-time container for buttons? - GALIAF95