How To Create New Controls At Runtime In VB.Net 2008

Q.:Write a Windows Application To Create New Controls At Runtime In VB.Net.

VB.Net allows to create required controls at run time, so that it uses full during fast software development.  The following code is used  to Create New Controls At Runtime In VB.Net 2008.

This is one of the most useful trick in VB.Net to create and enhance software development more easily.

Compability  :  Microsoft Visual Studio 2008 (Microsoft .Net Framework 3.5)

Source Code :

Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim i, a As Integer

        For i = 1 To 3
            a = i

            Select Case a
                Case 1
                    Dim textbox1 As New TextBox

                    textbox1.Text = "I am textbox"
                    textbox1.Location = New Point(100, 50)
                    textbox1.Size = New Size(100, 50)
                    Me.Controls.Add(textbox1)
                    a = 2
                Case 2
                    Dim checkbox1 As New CheckBox

                    checkbox1.Text = "I am checkbox"
                    checkbox1.Location = New Point(100, 20)
                    checkbox1.Size = New Size(100, 30)
                    Me.Controls.Add(checkbox1)

            End Select

        Next

    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        End
    End Sub

End Class

Output:

To Create New Control In VB.Net.bmp

Download Now (.Zip File 83 KB)…

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

CommentLuv badge
To use solvemedia you must get an API key from http://api.solvemedia.com/public/signup