Click here to Skip to main content
15,897,147 members
Articles / Programming Languages / Visual Basic

Alternative ways to instantiate objects

Rate me:
Please Sign up or sign in to vote.
4.76/5 (12 votes)
1 May 2012CPOL4 min read 38.8K   266   23  
Introduction for beginners on how to dynamically instantiate external types
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Partial Class frmMain
    Inherits System.Windows.Forms.Form

    'Form 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 Windows Form Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
    <System.Diagnostics.DebuggerStepThrough()> _
    Private Sub InitializeComponent()
        Me.Label1 = New System.Windows.Forms.Label()
        Me.lstSystemTypes = New System.Windows.Forms.ListBox()
        Me.btnCreateInstance = New System.Windows.Forms.Button()
        Me.txtAssemblyPath = New System.Windows.Forms.TextBox()
        Me.Panel1 = New System.Windows.Forms.Panel()
        Me.Label3 = New System.Windows.Forms.Label()
        Me.Label2 = New System.Windows.Forms.Label()
        Me.btnPickAssembly = New System.Windows.Forms.Button()
        Me.Label4 = New System.Windows.Forms.Label()
        Me.radReflection = New System.Windows.Forms.RadioButton()
        Me.radDeSerialization = New System.Windows.Forms.RadioButton()
        Me.Label5 = New System.Windows.Forms.Label()
        Me.SplitContainer1 = New System.Windows.Forms.SplitContainer()
        Me.PropertyGrid1 = New System.Windows.Forms.PropertyGrid()
        Me.Panel1.SuspendLayout()
        CType(Me.SplitContainer1, System.ComponentModel.ISupportInitialize).BeginInit()
        Me.SplitContainer1.Panel1.SuspendLayout()
        Me.SplitContainer1.Panel2.SuspendLayout()
        Me.SplitContainer1.SuspendLayout()
        Me.SuspendLayout()
        '
        'Label1
        '
        Me.Label1.AutoSize = True
        Me.Label1.Location = New System.Drawing.Point(12, 11)
        Me.Label1.Name = "Label1"
        Me.Label1.Size = New System.Drawing.Size(139, 13)
        Me.Label1.TabIndex = 1
        Me.Label1.Text = "Select an Assembly on disk:"
        '
        'lstSystemTypes
        '
        Me.lstSystemTypes.FormattingEnabled = True
        Me.lstSystemTypes.Location = New System.Drawing.Point(13, 71)
        Me.lstSystemTypes.Name = "lstSystemTypes"
        Me.lstSystemTypes.Size = New System.Drawing.Size(427, 69)
        Me.lstSystemTypes.TabIndex = 2
        '
        'btnCreateInstance
        '
        Me.btnCreateInstance.Enabled = False
        Me.btnCreateInstance.Location = New System.Drawing.Point(321, 170)
        Me.btnCreateInstance.Name = "btnCreateInstance"
        Me.btnCreateInstance.Size = New System.Drawing.Size(114, 23)
        Me.btnCreateInstance.TabIndex = 3
        Me.btnCreateInstance.Text = "Create Instance"
        Me.btnCreateInstance.UseVisualStyleBackColor = True
        '
        'txtAssemblyPath
        '
        Me.txtAssemblyPath.Location = New System.Drawing.Point(13, 29)
        Me.txtAssemblyPath.Name = "txtAssemblyPath"
        Me.txtAssemblyPath.Size = New System.Drawing.Size(392, 20)
        Me.txtAssemblyPath.TabIndex = 5
        '
        'Panel1
        '
        Me.Panel1.BackColor = System.Drawing.Color.White
        Me.Panel1.Controls.Add(Me.Label3)
        Me.Panel1.Controls.Add(Me.Label2)
        Me.Panel1.Dock = System.Windows.Forms.DockStyle.Top
        Me.Panel1.Location = New System.Drawing.Point(0, 0)
        Me.Panel1.Name = "Panel1"
        Me.Panel1.Size = New System.Drawing.Size(446, 57)
        Me.Panel1.TabIndex = 6
        '
        'Label3
        '
        Me.Label3.AutoSize = True
        Me.Label3.Location = New System.Drawing.Point(13, 29)
        Me.Label3.Name = "Label3"
        Me.Label3.Size = New System.Drawing.Size(358, 13)
        Me.Label3.TabIndex = 7
        Me.Label3.Text = "Select an assembly on disk and the type you want to create an object from"
        '
        'Label2
        '
        Me.Label2.AutoSize = True
        Me.Label2.Font = New System.Drawing.Font("Microsoft Sans Serif", 8.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.Label2.Location = New System.Drawing.Point(12, 9)
        Me.Label2.Name = "Label2"
        Me.Label2.Size = New System.Drawing.Size(101, 13)
        Me.Label2.TabIndex = 7
        Me.Label2.Text = "Object Inspector"
        '
        'btnPickAssembly
        '
        Me.btnPickAssembly.Location = New System.Drawing.Point(408, 27)
        Me.btnPickAssembly.Name = "btnPickAssembly"
        Me.btnPickAssembly.Size = New System.Drawing.Size(32, 23)
        Me.btnPickAssembly.TabIndex = 7
        Me.btnPickAssembly.Text = "..."
        Me.btnPickAssembly.UseVisualStyleBackColor = True
        '
        'Label4
        '
        Me.Label4.AutoSize = True
        Me.Label4.Location = New System.Drawing.Point(12, 55)
        Me.Label4.Name = "Label4"
        Me.Label4.Size = New System.Drawing.Size(107, 13)
        Me.Label4.TabIndex = 8
        Me.Label4.Text = "Choose System.Type"
        '
        'radReflection
        '
        Me.radReflection.AutoSize = True
        Me.radReflection.Checked = True
        Me.radReflection.Location = New System.Drawing.Point(12, 173)
        Me.radReflection.Name = "radReflection"
        Me.radReflection.Size = New System.Drawing.Size(73, 17)
        Me.radReflection.TabIndex = 9
        Me.radReflection.TabStop = True
        Me.radReflection.Text = "Reflection"
        Me.radReflection.UseVisualStyleBackColor = True
        '
        'radDeSerialization
        '
        Me.radDeSerialization.AutoSize = True
        Me.radDeSerialization.Location = New System.Drawing.Point(105, 173)
        Me.radDeSerialization.Name = "radDeSerialization"
        Me.radDeSerialization.Size = New System.Drawing.Size(93, 17)
        Me.radDeSerialization.TabIndex = 10
        Me.radDeSerialization.Text = "Deserialization"
        Me.radDeSerialization.UseVisualStyleBackColor = True
        '
        'Label5
        '
        Me.Label5.AutoSize = True
        Me.Label5.Location = New System.Drawing.Point(9, 151)
        Me.Label5.Name = "Label5"
        Me.Label5.Size = New System.Drawing.Size(104, 13)
        Me.Label5.TabIndex = 11
        Me.Label5.Text = "Instantiate by using: "
        '
        'SplitContainer1
        '
        Me.SplitContainer1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.SplitContainer1.Dock = System.Windows.Forms.DockStyle.Fill
        Me.SplitContainer1.Location = New System.Drawing.Point(0, 57)
        Me.SplitContainer1.Name = "SplitContainer1"
        Me.SplitContainer1.Orientation = System.Windows.Forms.Orientation.Horizontal
        '
        'SplitContainer1.Panel1
        '
        Me.SplitContainer1.Panel1.Controls.Add(Me.Label1)
        Me.SplitContainer1.Panel1.Controls.Add(Me.Label5)
        Me.SplitContainer1.Panel1.Controls.Add(Me.lstSystemTypes)
        Me.SplitContainer1.Panel1.Controls.Add(Me.radDeSerialization)
        Me.SplitContainer1.Panel1.Controls.Add(Me.btnCreateInstance)
        Me.SplitContainer1.Panel1.Controls.Add(Me.radReflection)
        Me.SplitContainer1.Panel1.Controls.Add(Me.txtAssemblyPath)
        Me.SplitContainer1.Panel1.Controls.Add(Me.Label4)
        Me.SplitContainer1.Panel1.Controls.Add(Me.btnPickAssembly)
        '
        'SplitContainer1.Panel2
        '
        Me.SplitContainer1.Panel2.Controls.Add(Me.PropertyGrid1)
        Me.SplitContainer1.Size = New System.Drawing.Size(446, 470)
        Me.SplitContainer1.SplitterDistance = 235
        Me.SplitContainer1.TabIndex = 12
        '
        'PropertyGrid1
        '
        Me.PropertyGrid1.Dock = System.Windows.Forms.DockStyle.Fill
        Me.PropertyGrid1.Location = New System.Drawing.Point(0, 0)
        Me.PropertyGrid1.Name = "PropertyGrid1"
        Me.PropertyGrid1.Size = New System.Drawing.Size(444, 229)
        Me.PropertyGrid1.TabIndex = 0
        '
        'frmMain
        '
        Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
        Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
        Me.ClientSize = New System.Drawing.Size(446, 527)
        Me.Controls.Add(Me.SplitContainer1)
        Me.Controls.Add(Me.Panel1)
        Me.Name = "frmMain"
        Me.Text = "Form1"
        Me.Panel1.ResumeLayout(False)
        Me.Panel1.PerformLayout()
        Me.SplitContainer1.Panel1.ResumeLayout(False)
        Me.SplitContainer1.Panel1.PerformLayout()
        Me.SplitContainer1.Panel2.ResumeLayout(False)
        CType(Me.SplitContainer1, System.ComponentModel.ISupportInitialize).EndInit()
        Me.SplitContainer1.ResumeLayout(False)
        Me.ResumeLayout(False)

    End Sub
    Friend WithEvents Label1 As System.Windows.Forms.Label
    Friend WithEvents lstSystemTypes As System.Windows.Forms.ListBox
    Friend WithEvents btnCreateInstance As System.Windows.Forms.Button
    Friend WithEvents txtAssemblyPath As System.Windows.Forms.TextBox
    Friend WithEvents Panel1 As System.Windows.Forms.Panel
    Friend WithEvents Label2 As System.Windows.Forms.Label
    Friend WithEvents Label3 As System.Windows.Forms.Label
    Friend WithEvents btnPickAssembly As System.Windows.Forms.Button
    Friend WithEvents Label4 As System.Windows.Forms.Label
    Friend WithEvents radReflection As System.Windows.Forms.RadioButton
    Friend WithEvents radDeSerialization As System.Windows.Forms.RadioButton
    Friend WithEvents Label5 As System.Windows.Forms.Label
    Friend WithEvents SplitContainer1 As System.Windows.Forms.SplitContainer
    Friend WithEvents PropertyGrid1 As System.Windows.Forms.PropertyGrid

End Class

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior)
Brazil Brazil
Coffe-addicted software developer since her 14's

Comments and Discussions