Question

In the WindowsForms what is the better way to initalize components:

  • in the properties window?
  • or in the code (in constructor)?

If I make it in the properties window, then I often have a situation, when I'm changing the value in the code and then closing the form. When I open it again, I'm getting old value (which I've written in properties) and it can confuse.

What is the differences between these two ways? Didn't found it in google.

Was it helpful?

Solution

It's equivalent.

  • When you change values using the properties window, that values are saved in the resx file. Then the method InitializeComponents(), that is written by the WinForms designed in the Form's constructor, performs the form initialization.

  • If you do it manually in the constructor, you must place your initialization code, after InitializeComponent() method, then, the form will be initialized with your values.

What method is better? In my opinion, both method are equivalent. You can choose the way you prefer. But my recommendation is not mix them. Use pure Winforms designer or pure code initialization.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top