When to use component?

JohanNL

Member
Joined
Jan 31, 2008
Messages
7
Programming Experience
10+
In VS.NET you can create a Class or a Component Class.
What is the difference?
 
The Component class has various special properties, each of which is specified in the MSDN Library topic for the Component class, most of which will mean nothing to you. The most immediately apparent property of the Component class is the fact that it can be added to the VS Toolbox and, subsequently, to a Form in the designer.
 
Just curious, is there more to the Component Class template than added "inherits component" to the class? Express doesn't have this template.
 
Just curious, is there more to the Component Class template than added "inherits component" to the class? Express doesn't have this template.
Adding a Component directly using the IDE creates a designer code file, just like adding a Form or UserControl. This is its default contents:
VB.NET:
Partial Class Component1
    Inherits System.ComponentModel.Component

    <System.Diagnostics.DebuggerNonUserCode()> _
    Public Sub New(ByVal container As System.ComponentModel.IContainer)
        MyClass.New()

        'Required for Windows.Forms Class Composition Designer support
        If (container IsNot Nothing) Then
            container.Add(Me)
        End If

    End Sub

    <System.Diagnostics.DebuggerNonUserCode()> _
    Public Sub New()
        MyBase.New()

        'This call is required by the Component Designer.
        InitializeComponent()

    End Sub

    'Component overrides dispose to clean up the component list.
    <System.Diagnostics.DebuggerNonUserCode()> _
    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

    'Required by the Component Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Component Designer
    'It can be modified using the Component Designer.
    'Do not modify it using the code editor.
    <System.Diagnostics.DebuggerStepThrough()> _
    Private Sub InitializeComponent()
        components = New System.ComponentModel.Container()
    End Sub

End Class
 
Back
Top