What's the purpose of the components IContainer generated by the Winforms designer?

后端 未结 2 2009
梦如初夏
梦如初夏 2020-12-25 10:58

When you create a new form in Visual Studio, the designer generates the following code in the .Designer.cs file:

  /// 
  /// Required designe         


        
2条回答
  •  抹茶落季
    2020-12-25 10:58

    When you add non-UI components to the form (such as a Timer component), components will be the parent of those compoments. The code in the designer file makes sure that these components are disposed of when the form is disposed. If you have not added any such components to the form in design time, components will be null.

    Since components is designer generated, and will be null if you have no non-UI compoments on the form (in design time), I would personally opt for managing those components in some other way, disposing them on form close or something like that.

提交回复
热议问题