Is components as Container needed for all custom controls?

Peter Volz 1,295 Reputation points
2023-04-12T02:30:51.5933333+00:00

Hello, I'm learning designing of .net framework WinForms controls In a custom control I've seen:

Private components As System.ComponentModel.IContainer

and:

    Protected Overrides Sub Dispose(ByVal Disposing As Boolean)
        Try
            If Disposing AndAlso components IsNot Nothing Then
                components.Dispose()
            End If
        Finally
            MyBase.Dispose(Disposing)
        End Try
    End Sub

also in Private Sub InitializeComponent() :

Me.components = New System.ComponentModel.Container()

But this custom control has an ImageList component When designing my own custom control, which does not have any component (such as Image List) should I still insert the above code to my custom control? My custom control inherits the Panel with 1 Button and 1 TextBox inside, nothing more.

C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,391 questions
VB
VB
An object-oriented programming language developed by Microsoft that is implemented on the .NET Framework. Previously known as Visual Basic .NET.
2,608 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Castorix31 82,121 Reputation points
    2023-04-12T05:30:48.1066667+00:00

    No, it is not needed. You can see MSDN samples for basic Custom Controls, like : How to: Develop a Simple Windows Forms Control

    1 person found this answer helpful.