S
S
sivabur2015-05-09 14:01:18
.NET
sivabur, 2015-05-09 14:01:18

Where is the best place to create invisible controls?

Where is it better to create invisible controls (timer, backgrounwworker etc)
Dynamically in the code or transfer from the toolbar (ToolBox)?
Best practices, so to speak)
When many elements are different / identical / when there are few elements / how it is displayed on performance (or performance does not play a role here)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Stanislav Silin, 2015-05-09
@sivabur

In principle, there is a difference, but it all depends on what you want to do.
If you add via a constructor, then it is created and initialized in Form1.Designer.cs when the form is run.
If in code, then where you want, when you want and how you want.
If there is only one element, then you can simply drag it onto the form, but if there are 100500+ of them, then it will be much easier to initialize from the loop, simultaneously stuffing it into some kind of array.
It is worth noting that the added components in the constructor will die along with the form, and those made in the code will live until the garbage collector removes them or you delete them.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question