Click here to Skip to main content
15,888,521 members
Articles / Programming Languages / Visual Basic

Automate code-writing in VB.NET control's development

Rate me:
Please Sign up or sign in to vote.
4.89/5 (11 votes)
11 Aug 20042 min read 60.5K   1.1K   41  
Utility for automating code writing for VB.NET control's developers
Imports System.Reflection
Imports System.ComponentModel
Imports System.Text.RegularExpressions

Public Class FrmMain
    Inherits System.Windows.Forms.Form

#Region "VS IDE Autogenerated code"

    Public Sub New()
        MyBase.New()
        InitializeComponent()
    End Sub

    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub

    Private components As System.ComponentModel.IContainer
    Private WithEvents TextBox1 As System.Windows.Forms.TextBox
    Private WithEvents TreeView1 As System.Windows.Forms.TreeView
    Private WithEvents GroupBox1 As System.Windows.Forms.GroupBox
    Private WithEvents txtPrefix As System.Windows.Forms.TextBox
    Private WithEvents Panel1 As System.Windows.Forms.Panel
    Private WithEvents pnlLang As System.Windows.Forms.Panel
    Private WithEvents Label2 As System.Windows.Forms.Label
    Private WithEvents grpPrefix As System.Windows.Forms.GroupBox
    Private WithEvents btnApplyPrefix As System.Windows.Forms.Button
    Private WithEvents cmbLanguage As System.Windows.Forms.ComboBox
    Private WithEvents Splitter1 As System.Windows.Forms.Splitter
    Private WithEvents StatusBar1 As System.Windows.Forms.StatusBar
    Private WithEvents cmbNames As System.Windows.Forms.ComboBox
    Private WithEvents AppMenu As System.Windows.Forms.MainMenu
    Private WithEvents MenuImage1 As System.Windows.Forms.MenuImage
    Private WithEvents MnuFile As System.Windows.Forms.MenuItem
    Private WithEvents MnuCopy As System.Windows.Forms.MenuItem
    Private WithEvents MnuCopySel As System.Windows.Forms.MenuItem
    Private WithEvents MnuExit As System.Windows.Forms.MenuItem
    Private WithEvents ImageList1 As System.Windows.Forms.ImageList
    Private WithEvents mnuView0 As System.Windows.Forms.MenuItem
    Private WithEvents mnuView1 As System.Windows.Forms.MenuItem
    Private WithEvents mnuView2 As System.Windows.Forms.MenuItem
    Private WithEvents mnuViewParent As System.Windows.Forms.MenuItem
    Private WithEvents MenuItem2 As System.Windows.Forms.MenuItem
    Private WithEvents MnuOpen As System.Windows.Forms.MenuItem
    Private WithEvents MnuSave As System.Windows.Forms.MenuItem

    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.components = New System.ComponentModel.Container
        Dim resources As System.Resources.ResourceManager = New System.Resources.ResourceManager(GetType(FrmMain))
        Me.TextBox1 = New System.Windows.Forms.TextBox
        Me.TreeView1 = New System.Windows.Forms.TreeView
        Me.ImageList1 = New System.Windows.Forms.ImageList(Me.components)
        Me.GroupBox1 = New System.Windows.Forms.GroupBox
        Me.txtPrefix = New System.Windows.Forms.TextBox
        Me.Panel1 = New System.Windows.Forms.Panel
        Me.cmbNames = New System.Windows.Forms.ComboBox
        Me.grpPrefix = New System.Windows.Forms.GroupBox
        Me.btnApplyPrefix = New System.Windows.Forms.Button
        Me.pnlLang = New System.Windows.Forms.Panel
        Me.cmbLanguage = New System.Windows.Forms.ComboBox
        Me.Label2 = New System.Windows.Forms.Label
        Me.Splitter1 = New System.Windows.Forms.Splitter
        Me.StatusBar1 = New System.Windows.Forms.StatusBar
        Me.AppMenu = New System.Windows.Forms.MainMenu
        Me.MnuFile = New System.Windows.Forms.MenuItem
        Me.MnuOpen = New System.Windows.Forms.MenuItem
        Me.MnuCopy = New System.Windows.Forms.MenuItem
        Me.MnuCopySel = New System.Windows.Forms.MenuItem
        Me.MnuSave = New System.Windows.Forms.MenuItem
        Me.MenuItem2 = New System.Windows.Forms.MenuItem
        Me.MnuExit = New System.Windows.Forms.MenuItem
        Me.mnuViewParent = New System.Windows.Forms.MenuItem
        Me.mnuView0 = New System.Windows.Forms.MenuItem
        Me.mnuView1 = New System.Windows.Forms.MenuItem
        Me.mnuView2 = New System.Windows.Forms.MenuItem
        Me.MenuImage1 = New System.Windows.Forms.MenuImage(Me.components)
        Me.GroupBox1.SuspendLayout()
        Me.Panel1.SuspendLayout()
        Me.grpPrefix.SuspendLayout()
        Me.pnlLang.SuspendLayout()
        Me.SuspendLayout()
        '
        'TextBox1
        '
        Me.TextBox1.Dock = System.Windows.Forms.DockStyle.Fill
        Me.TextBox1.Font = New System.Drawing.Font("Courier New", 9.75!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.TextBox1.Location = New System.Drawing.Point(0, 85)
        Me.TextBox1.Multiline = True
        Me.TextBox1.Name = "TextBox1"
        Me.TextBox1.ScrollBars = System.Windows.Forms.ScrollBars.Both
        Me.TextBox1.Size = New System.Drawing.Size(304, 274)
        Me.TextBox1.TabIndex = 1
        Me.TextBox1.Text = ""
        '
        'TreeView1
        '
        Me.TreeView1.Dock = System.Windows.Forms.DockStyle.Fill
        Me.TreeView1.ImageIndex = 5
        Me.TreeView1.ImageList = Me.ImageList1
        Me.TreeView1.Location = New System.Drawing.Point(3, 16)
        Me.TreeView1.Name = "TreeView1"
        Me.TreeView1.Size = New System.Drawing.Size(186, 340)
        Me.TreeView1.TabIndex = 3
        '
        'ImageList1
        '
        Me.ImageList1.ImageSize = New System.Drawing.Size(16, 16)
        Me.ImageList1.ImageStream = CType(resources.GetObject("ImageList1.ImageStream"), System.Windows.Forms.ImageListStreamer)
        Me.ImageList1.TransparentColor = System.Drawing.Color.Transparent
        '
        'GroupBox1
        '
        Me.GroupBox1.Controls.Add(Me.TreeView1)
        Me.GroupBox1.Dock = System.Windows.Forms.DockStyle.Left
        Me.GroupBox1.Location = New System.Drawing.Point(0, 0)
        Me.GroupBox1.Name = "GroupBox1"
        Me.GroupBox1.Size = New System.Drawing.Size(192, 359)
        Me.GroupBox1.TabIndex = 4
        Me.GroupBox1.TabStop = False
        Me.GroupBox1.Text = "Objects"
        '
        'txtPrefix
        '
        Me.txtPrefix.Dock = System.Windows.Forms.DockStyle.Fill
        Me.txtPrefix.Location = New System.Drawing.Point(3, 16)
        Me.txtPrefix.Name = "txtPrefix"
        Me.txtPrefix.Size = New System.Drawing.Size(218, 20)
        Me.txtPrefix.TabIndex = 5
        Me.txtPrefix.Text = ""
        '
        'Panel1
        '
        Me.Panel1.Controls.Add(Me.TextBox1)
        Me.Panel1.Controls.Add(Me.cmbNames)
        Me.Panel1.Controls.Add(Me.grpPrefix)
        Me.Panel1.Controls.Add(Me.pnlLang)
        Me.Panel1.Dock = System.Windows.Forms.DockStyle.Fill
        Me.Panel1.Location = New System.Drawing.Point(192, 0)
        Me.Panel1.Name = "Panel1"
        Me.Panel1.Size = New System.Drawing.Size(304, 359)
        Me.Panel1.TabIndex = 6
        '
        'cmbNames
        '
        Me.cmbNames.Dock = System.Windows.Forms.DockStyle.Top
        Me.cmbNames.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList
        Me.cmbNames.Location = New System.Drawing.Point(0, 64)
        Me.cmbNames.Name = "cmbNames"
        Me.cmbNames.Size = New System.Drawing.Size(304, 21)
        Me.cmbNames.TabIndex = 11
        '
        'grpPrefix
        '
        Me.grpPrefix.Controls.Add(Me.txtPrefix)
        Me.grpPrefix.Controls.Add(Me.btnApplyPrefix)
        Me.grpPrefix.Dock = System.Windows.Forms.DockStyle.Top
        Me.grpPrefix.Location = New System.Drawing.Point(0, 24)
        Me.grpPrefix.Name = "grpPrefix"
        Me.grpPrefix.Size = New System.Drawing.Size(304, 40)
        Me.grpPrefix.TabIndex = 10
        Me.grpPrefix.TabStop = False
        Me.grpPrefix.Text = "Properties Prefix"
        '
        'btnApplyPrefix
        '
        Me.btnApplyPrefix.Dock = System.Windows.Forms.DockStyle.Right
        Me.btnApplyPrefix.Location = New System.Drawing.Point(221, 16)
        Me.btnApplyPrefix.Name = "btnApplyPrefix"
        Me.btnApplyPrefix.Size = New System.Drawing.Size(80, 21)
        Me.btnApplyPrefix.TabIndex = 6
        Me.btnApplyPrefix.Text = "Apply Prefix"
        '
        'pnlLang
        '
        Me.pnlLang.Controls.Add(Me.cmbLanguage)
        Me.pnlLang.Controls.Add(Me.Label2)
        Me.pnlLang.Dock = System.Windows.Forms.DockStyle.Top
        Me.pnlLang.Location = New System.Drawing.Point(0, 0)
        Me.pnlLang.Name = "pnlLang"
        Me.pnlLang.Size = New System.Drawing.Size(304, 24)
        Me.pnlLang.TabIndex = 9
        '
        'cmbLanguage
        '
        Me.cmbLanguage.Dock = System.Windows.Forms.DockStyle.Fill
        Me.cmbLanguage.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList
        Me.cmbLanguage.Items.AddRange(New Object() {"English (en-UK)", "Italian (it-IT)", "French (fr-FR)", "German (de-DE)"})
        Me.cmbLanguage.Location = New System.Drawing.Point(96, 0)
        Me.cmbLanguage.Name = "cmbLanguage"
        Me.cmbLanguage.Size = New System.Drawing.Size(208, 21)
        Me.cmbLanguage.TabIndex = 10
        '
        'Label2
        '
        Me.Label2.Dock = System.Windows.Forms.DockStyle.Left
        Me.Label2.Location = New System.Drawing.Point(0, 0)
        Me.Label2.Name = "Label2"
        Me.Label2.Size = New System.Drawing.Size(96, 24)
        Me.Label2.TabIndex = 9
        Me.Label2.Text = "choose language"
        Me.Label2.TextAlign = System.Drawing.ContentAlignment.MiddleLeft
        '
        'Splitter1
        '
        Me.Splitter1.Location = New System.Drawing.Point(192, 0)
        Me.Splitter1.Name = "Splitter1"
        Me.Splitter1.Size = New System.Drawing.Size(3, 359)
        Me.Splitter1.TabIndex = 4
        Me.Splitter1.TabStop = False
        '
        'StatusBar1
        '
        Me.StatusBar1.Location = New System.Drawing.Point(0, 359)
        Me.StatusBar1.Name = "StatusBar1"
        Me.StatusBar1.Size = New System.Drawing.Size(496, 22)
        Me.StatusBar1.TabIndex = 4
        '
        'AppMenu
        '
        Me.AppMenu.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.MnuFile, Me.mnuViewParent})
        '
        'MnuFile
        '
        Me.MnuFile.Index = 0
        Me.MnuFile.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.MnuOpen, Me.MnuCopy, Me.MnuCopySel, Me.MnuSave, Me.MenuItem2, Me.MnuExit})
        Me.MnuFile.Text = "File"
        '
        'MnuOpen
        '
        Me.MnuOpen.Index = 0
        Me.MenuImage1.SetMenuImage(Me.MnuOpen, "7")
        Me.MnuOpen.OwnerDraw = True
        Me.MnuOpen.Text = "Get references from an Assemby"
        '
        'MnuCopy
        '
        Me.MnuCopy.Index = 1
        Me.MenuImage1.SetMenuImage(Me.MnuCopy, "0")
        Me.MnuCopy.OwnerDraw = True
        Me.MnuCopy.Shortcut = System.Windows.Forms.Shortcut.CtrlC
        Me.MnuCopy.Text = "Copy all code"
        '
        'MnuCopySel
        '
        Me.MnuCopySel.Index = 2
        Me.MenuImage1.SetMenuImage(Me.MnuCopySel, "0")
        Me.MnuCopySel.OwnerDraw = True
        Me.MnuCopySel.Shortcut = System.Windows.Forms.Shortcut.CtrlShiftC
        Me.MnuCopySel.Text = "Copy selected code"
        '
        'MnuSave
        '
        Me.MnuSave.Index = 3
        Me.MenuImage1.SetMenuImage(Me.MnuSave, "8")
        Me.MnuSave.OwnerDraw = True
        Me.MnuSave.Text = "Save"
        '
        'MenuItem2
        '
        Me.MenuItem2.Index = 4
        Me.MenuImage1.SetMenuImage(Me.MenuItem2, Nothing)
        Me.MenuItem2.OwnerDraw = True
        Me.MenuItem2.Text = "-"
        '
        'MnuExit
        '
        Me.MnuExit.Index = 5
        Me.MenuImage1.SetMenuImage(Me.MnuExit, "1")
        Me.MnuExit.OwnerDraw = True
        Me.MnuExit.Text = "Exit"
        '
        'mnuViewParent
        '
        Me.mnuViewParent.Index = 1
        Me.mnuViewParent.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.mnuView0, Me.mnuView1, Me.mnuView2})
        Me.mnuViewParent.Text = "View"
        '
        'mnuView0
        '
        Me.mnuView0.Checked = True
        Me.mnuView0.Index = 0
        Me.MenuImage1.SetMenuImage(Me.mnuView0, Nothing)
        Me.mnuView0.OwnerDraw = True
        Me.mnuView0.Text = "All objects"
        '
        'mnuView1
        '
        Me.mnuView1.Index = 1
        Me.MenuImage1.SetMenuImage(Me.mnuView1, Nothing)
        Me.mnuView1.OwnerDraw = True
        Me.mnuView1.Text = "Only inherits from Component"
        '
        'mnuView2
        '
        Me.mnuView2.Index = 2
        Me.MenuImage1.SetMenuImage(Me.mnuView2, Nothing)
        Me.mnuView2.OwnerDraw = True
        Me.mnuView2.Text = "Only inherits from Control"
        '
        'MenuImage1
        '
        Me.MenuImage1.ImageList = Me.ImageList1
        '
        'FrmMain
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.ClientSize = New System.Drawing.Size(496, 381)
        Me.Controls.Add(Me.Splitter1)
        Me.Controls.Add(Me.Panel1)
        Me.Controls.Add(Me.GroupBox1)
        Me.Controls.Add(Me.StatusBar1)
        Me.Icon = CType(resources.GetObject("$this.Icon"), System.Drawing.Icon)
        Me.Location = New System.Drawing.Point(5, 2)
        Me.Menu = Me.AppMenu
        Me.Name = "FrmMain"
        Me.Text = "Class Inspector"
        Me.GroupBox1.ResumeLayout(False)
        Me.Panel1.ResumeLayout(False)
        Me.grpPrefix.ResumeLayout(False)
        Me.pnlLang.ResumeLayout(False)
        Me.ResumeLayout(False)

    End Sub

#End Region

#Region "Properties and fields"
    'this IDS will appears in language combobox
    'descriptions are defined in combo Items property
    Private languageIDS() As String = {"en-US", "it-IT", "fr-FR", "de-DE"}

    Private InheritTypeArray() As Type = {Nothing, GetType(Component), GetType(Control)}
    Private InheritType As Type ' type of which must inherits classes inspected
    Private currentType As Type ' type currently Inspected
    Private currentText As String ' code currently generated

    'MethodInvokers
    Dim treeFiller As New MethodInvoker(AddressOf FillTypeTree)
    Dim showControlPropsInvoker As New MethodInvoker(AddressOf showControlPropsCall)
    Dim ClearStatusBarInvoker As New MethodInvoker(AddressOf ClearStatusBar)

    'default AssemblyName array (this assembly AssemblyNames)
    Private _asmNames As AssemblyName() = Me.GetType.Assembly.GetReferencedAssemblies
    'AssemblyName array  property
    Private Property asmNames() As AssemblyName()
        Get
            Return _asmNames
        End Get
        Set(ByVal Value As AssemblyName())
            _asmNames = Value
        End Set
    End Property

    'Prefix for properties names on code generation
    Private ReadOnly Property Prefix() As String
        Get
            Return txtPrefix.Text
        End Get
    End Property
#End Region

    'method for filling Treeview
#Region "FillTypeTree"
    Private Sub FillTypeTree()
        TreeView1.Sorted = True
        TreeView1.Nodes.Clear()
        TreeView1.LabelEdit = False
        For Each asmName As AssemblyName In asmNames
            Dim ASM As [Assembly]
            Try
                ASM = [Assembly].Load(asmName)
                Dim types() As Type = ASM.GetTypes
                For Each t As Type In types
                    If t.IsPublic Then
                        If Not InheritType Is Nothing Then
                            If Not t.IsSubclassOf(InheritType) Then
                                GoTo endfor
                            End If
                        End If
                        If Not t.IsEnum And Not t.IsClass Then
                            GoTo endfor
                        End If
                        If (t.IsValueType Or t.IsCOMObject) And Not t.IsEnum Then
                            GoTo endfor
                        End If
                        Dim NSNd As TreeNode
                        If Not t.Namespace = String.Empty Then
                            For Each nd As TreeNode In TreeView1.Nodes
                                If nd.Text = t.Namespace.ToString Then
                                    NSNd = nd
                                    Exit For
                                End If
                            Next
                            If IsNothing(NSNd) Then
                                NSNd = New TreeNode
                                NSNd.Text = t.Namespace.ToString
                                NSNd.ImageIndex = 4
                                NSNd.SelectedImageIndex = 4
                                TreeView1.Nodes.Add(NSNd)
                            End If
                        End If
                        If Not t.Namespace = "" Then
                            Dim TpNd As New TreeNode
                            With TpNd
                                .ImageIndex = 5
                                If t.IsSubclassOf(GetType(Component)) Then .ImageIndex = 2
                                If t.IsSubclassOf(GetType(Control)) Then .ImageIndex = 3
                                If t.IsEnum Then
                                    .ImageIndex = 6
                                End If
                                .SelectedImageIndex = .ImageIndex
                                .Text = t.Name
                                .Tag = t
                            End With
                            NSNd.Nodes.Add(TpNd)
                            NSNd = Nothing
                        End If
                    End If
endfor:
                Next
            Catch ex As Exception

            End Try
        Next
        TreeView1.Invalidate()
    End Sub
#End Region

    'function for extract some attributes from PropertyInfo
#Region "Function attributesBuild"
    Private Function attributesBuild(ByVal p As PropertyInfo) As String
        Dim defaultValue As Object = ""
        Dim Description As String
        Dim sb As New System.Text.StringBuilder
        Dim sbComment As New System.Text.StringBuilder
        Dim attrs() As Object = p.GetCustomAttributes(True)
        Dim attrsList As New ArrayList
        sbComment.AppendFormat("'Attributi per {0}{1}", p.Name, vbNewLine)
        For Each A As Attribute In attrs
            sbComment.AppendFormat("'{0}{1}", A.GetType.Name, vbNewLine)
            If TypeOf A Is DefaultValueAttribute Then
                defaultValue = CType(A, DefaultValueAttribute).Value
                If TypeOf defaultValue Is String Then
                    defaultValue = """" & defaultValue & """"
                End If
                attrsList.Add(String.Format("DefaultValue({0})", defaultValue))
            ElseIf TypeOf A Is DescriptionAttribute Then
                Description = CType(A, DescriptionAttribute).Description
                attrsList.Add(String.Format("Description(""{0}"")", Description))
            ElseIf TypeOf A Is DesignerSerializationVisibilityAttribute Then
                Dim DVA As DesignerSerializationVisibilityAttribute = A
                attrsList.Add(String.Format("DesignerSerializationVisibility({0})", DVA.Visibility.ToString))
            ElseIf TypeOf A Is BrowsableAttribute Then
                attrsList.Add(String.Format("Browsable({0})", CType(A, BrowsableAttribute).Browsable))
            End If
        Next
        If attrsList.Count = 0 Then
            Return ""
        End If
        Dim ssAttrs() As String = attrsList.ToArray(GetType(String))
        sb.Append("<")
        sb.Append(String.Join(",", ssAttrs))
        sb.Append("> _")
        sb.Append(vbNewLine)
        Return sb.ToString
    End Function
#End Region

    'method for parse ENUM type
#Region "showEnum"
    Private Sub showEnum(ByVal T As Type)
        Dim sb As New System.Text.StringBuilder
        Dim enumNames() As String = System.Enum.GetNames(T)
        Dim enumValues As Array = System.Enum.GetValues(T)
        Dim tName As String = System.Enum.GetUnderlyingType(T).Name
        Dim pName As String = Prefix & T.Name
        sb.AppendFormat("Public Enum {0} As {1}{2}", pName, tName, vbNewLine)
        Dim i As Integer = 0
        For Each nm As String In enumNames
            Dim v As Object = CInt(enumValues(i))

            sb.AppendFormat("{0}=H&{1}'{2}{3}", nm, Hex(v), v, vbNewLine)
            i += 1
        Next
        sb.AppendFormat("End Enum{0}", vbNewLine)
        currentText = sb.ToString
        TextBox1.Text = currentText
    End Sub
#End Region
    'method for parse any else CLASS type

#Region "showControlProps"

    Private Sub showControlProps(ByVal T As Type)
        If T.IsEnum Then
            showEnum(T)
            Exit Sub
        End If

        Dim sb As New System.Text.StringBuilder
        Dim props() As PropertyInfo = T.GetProperties()
        Dim propsList As New ArrayList(props)
        propsList.Sort(New PropsComparer)
        cmbNames.DataSource = propsList
        For Each p As PropertyInfo In propsList
            Dim pName As String = Prefix & p.Name
            Dim pType As String = p.PropertyType.ToString.Replace("[", "(").Replace("]", ")")
            pType = pType.Replace("+", ".")
            Dim ro As String = ""
            If Not p.CanWrite Then
                ro = "ReadOnly"
            End If
            sb.AppendFormat("'{0}", vbNewLine)
            sb.AppendFormat("'{0}{1}", p.Name, vbNewLine)
            sb.AppendFormat("'{0}", vbNewLine)
            sb.AppendFormat("Private _{0} as {1}{2}", pName, pType, vbNewLine)

            sb.Append(attributesBuild(p))
            sb.AppendFormat("Public {0} Property {1} as {2}{3}", ro, pName, pType, vbNewLine)
            sb.AppendFormat("   Get{0}", vbNewLine)
            sb.AppendFormat("       return _{0}{1}", pName, vbNewLine)
            sb.AppendFormat("   End Get{0}", vbNewLine)
            If p.CanWrite Then
                sb.AppendFormat("   Set (Value as {0}){1}", pType, vbNewLine)
                sb.AppendFormat("       _{0}=Value{1}", pName, vbNewLine)
                sb.AppendFormat("   End Set{0}", vbNewLine)
            End If
            sb.AppendFormat("End Property{0}", vbNewLine)
            sb.AppendFormat("{0}", vbNewLine)
        Next
        currentText = sb.ToString
        TextBox1.Text = currentText
    End Sub

    'Method called by MethodInvoker showControlPropsInvoker
    Private Sub showControlPropsCall()
        If Not IsNothing(currentType) Then
            showControlProps(currentType)
        End If
    End Sub
#End Region


#Region "Form and controls Event Handlers"
    Private Sub Form_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Me.cmbLanguage.SelectedIndex = 0
        Me.BeginInvoke(treeFiller)
    End Sub

    Private Sub TreeView1_AfterSelect(ByVal sender As System.Object, ByVal e As System.Windows.Forms.TreeViewEventArgs) Handles TreeView1.AfterSelect
        If TypeOf e.Node.Tag Is Type Then
            currentType = e.Node.Tag
            Me.BeginInvoke(showControlPropsInvoker)
        End If
    End Sub


    Private Sub cmbLanguage_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmbLanguage.SelectedIndexChanged
        Dim lang As String = languageIDS(cmbLanguage.SelectedIndex)
        Threading.Thread.CurrentThread.CurrentUICulture = New Globalization.CultureInfo(lang)
        If Me.IsHandleCreated Then
            Me.BeginInvoke(showControlPropsInvoker)
        End If
    End Sub


    Private Sub btnApplyPrefix_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnApplyPrefix.Click
        Me.BeginInvoke(showControlPropsInvoker)
    End Sub


    Private Sub cmbNames_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmbNames.SelectedIndexChanged
        Try
            Dim TypeName As String = cmbNames.Items(cmbNames.SelectedIndex).Name

            'Dim TypeName As String = SelectedText.Split(" ")(1)
            Dim i, l As Integer
            Dim pattern As String = "'" & TypeName
            Dim m, m2 As Match
            m = Regex.Match(currentText, pattern)
            i = m.Index
            pattern = "End Property"
            Dim subText As String = currentText.Substring(i)
            m2 = Regex.Match(subText, pattern, RegexOptions.Multiline)
            l = (i + m2.Index + m2.Length) - i
            TextBox1.Focus()
            TextBox1.Select(i, l)
            TextBox1.ScrollToCaret()
        Catch ex As Exception
        End Try
    End Sub

    Private Sub mnuView_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuView0.Click, mnuView1.Click, mnuView2.Click
        Try
            Dim i As Integer = sender.index
            InheritType = InheritTypeArray(i)
            For Each mi As MenuItem In mnuViewParent.MenuItems
                If mi.Index = i Then
                    mi.Checked = True
                Else
                    mi.Checked = False
                End If
            Next
            If Me.IsHandleCreated Then
                Me.BeginInvoke(treeFiller)
            End If
        Catch ex As Exception
            MsgBox(ex.ToString)
        End Try

    End Sub

    Private Sub MnuOpen_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MnuOpen.Click
        Dim fd As New OpenFileDialog
        Dim fileName As String
        With fd
            .RestoreDirectory = True
            .CheckFileExists = True
            .Multiselect = False
            .Filter = "DLL and EXE (*.dll;*.exe)|*.dll;*.exe"
            If .ShowDialog = DialogResult.OK Then
                fileName = .FileName
            End If
        End With
        Try
            Dim ASM As [Assembly]
            ASM = [Assembly].LoadFile(fileName)
            Me.asmNames = ASM.GetReferencedAssemblies
            Me.BeginInvoke(treeFiller)
        Catch ex As Exception
            MsgBox(String.Format("Program cannot load assembly {0}", fileName), MsgBoxStyle.Critical, "Error")
        End Try
    End Sub
    Private Sub MnuCopy_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MnuCopy.Click
        Dim textToCopy As String = TextBox1.Text
        If textToCopy Is Nothing Then Exit Sub
        Clipboard.SetDataObject("")
        Clipboard.SetDataObject(textToCopy, True)
        StatusBar1.Text = "Code copied!"
        StartClearStatusBar()
    End Sub
    Private Sub MnuCopySel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MnuCopySel.Click
        Dim textToCopy As String = TextBox1.SelectedText
        If textToCopy Is Nothing Then Exit Sub
        Clipboard.SetDataObject("")
        Clipboard.SetDataObject(textToCopy, True)
        StatusBar1.Text = "Selected code copied!"
        StartClearStatusBar()
    End Sub
    Private Sub MnuSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MnuSave.Click
        If currentText Is Nothing Then
            Exit Sub
        End If
        Dim fd As New SaveFileDialog
        Dim fileName As String
        With fd
            .FileName = currentType.Name & ".txt"
            .RestoreDirectory = True
            .CheckFileExists = False
            .AddExtension = True
            .Filter = "Text file (*.txt)|*.txt|All files (*.*)|*.*"
            If .ShowDialog = DialogResult.OK Then
                fileName = .FileName
            End If
        End With
        Try
            If IO.File.Exists(fileName) Then
                IO.File.Delete(fileName)
            End If
            Dim sw As IO.StreamWriter = IO.File.CreateText(fileName)
            sw.Write(currentText)
            sw.Close()
            StatusBar1.Text = String.Format("Code saved in {0}!", fileName)
        Catch ex As Exception
            StatusBar1.Text = String.Format("Error for save file {0}: {1}!", fileName, ex.Message)
        End Try

        StartClearStatusBar()
    End Sub

    Private Sub MnuExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MnuExit.Click
        Application.Exit()
    End Sub
#End Region

#Region "tecnique for hiding status bar message"

    Private Sub ClearStatusBar()
        StatusBar1.Text = ""
    End Sub

    Private Sub ClearStatusBarCaller()
        Try
            StatusBar1.BeginInvoke(ClearStatusBarInvoker)
        Catch ex As Exception
        End Try
    End Sub

    Private Sub StartClearStatusBar()
        Dim sbc As New StatusBarClear
        AddHandler sbc.Stop, AddressOf ClearStatusBarCaller
        Dim T As New Threading.Thread(AddressOf sbc.run)
        T.Start()
    End Sub
#End Region

#Region "internal classes"
    'comparer for propertyInfo collections
#Region "internal class PropsComparer"
    Private Class PropsComparer
        Implements IComparer

        Public Function Compare(ByVal x As Object, ByVal y As Object) As Integer Implements System.Collections.IComparer.Compare
            Return String.Compare(x.Name, y.Name)
        End Function
    End Class
#End Region
    'class to define timer stop for status bar message showing
#Region "internal class StatusBarClear"
    Private Class StatusBarClear
        Public Event [Stop]()

        Public Sub run()
            Threading.Thread.CurrentThread.Sleep(2000)
            RaiseEvent Stop()
        End Sub
    End Class
#End Region
#End Region
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 has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Web Developer
Italy Italy
Francesco Smelzo is a free-lance developer that live and work in Italy,he is specialized on microsoft platform development and in web projects.

He is specially skilled on VB.NET, XML,XSL and most of web scripting languages.

Comments and Discussions