title: Is there a way in VB.NET to have buttons and menu bars that are built in the code show up in the design view?
body: <p>Is there a way in VB.NET to make components like buttons and menus bars show in design view of you added them in programmatically?</p>
  
  <p>I now in Java i you add a button in the code it will show in design view if you switch back and forth. Can this be done in VB.NET.</p>
  
  <p>Code:</p>
  
  <pre><code>Imports System.IO
  
  Public Class Form1
      Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
          'defining the main menu bar
          Dim mnuBar As New MainMenu()
          'defining the menu items for the main menu bar
          Dim myMenuItemFile As New MenuItem("&amp;File")
          Dim myMenuItemEdit As New MenuItem("&amp;Edit")
          Dim myMenuItemView As New MenuItem("&amp;View")
          Dim myMenuItemProject As New MenuItem("&amp;Project")
  
          'adding the menu items to the main menu bar
          mnuBar.MenuItems.Add(myMenuItemFile)
          mnuBar.MenuItems.Add(myMenuItemEdit)
          mnuBar.MenuItems.Add(myMenuItemView)
          mnuBar.MenuItems.Add(myMenuItemProject)
  
          ' defining some sub menus
          Dim myMenuItemNew As New MenuItem("&amp;New")
          Dim myMenuItemOpen As New MenuItem("&amp;Open")
          Dim myMenuItemSave As New MenuItem("&amp;Save")
  
          'add sub menus to the File menu
          myMenuItemFile.MenuItems.Add(myMenuItemNew)
          myMenuItemFile.MenuItems.Add(myMenuItemOpen)
          myMenuItemFile.MenuItems.Add(myMenuItemSave)
  
          'add the main menu to the form
          Me.Menu = mnuBar
  
          ' Set the caption bar text of the form.  
          Me.Text = "tutorialspoint.com"
  
          'create a new TreeView
          Dim TreeView1 As TreeView
          TreeView1 = New TreeView()
          TreeView1.Location = New Point(5, 30)
          TreeView1.Size = New Size(150, 150)
          Me.Controls.Add(TreeView1)
          TreeView1.Nodes.Clear()
          'Creating the root node
          Dim root = New TreeNode("Application")
          TreeView1.Nodes.Add(root)
          TreeView1.Nodes(0).Nodes.Add(New TreeNode("Project 1"))
          'Creating child nodes under the first child
          For loopindex As Integer = 1 To 4
              TreeView1.Nodes(0).Nodes(0).Nodes.Add(New  _
                  TreeNode("Sub Project" &amp; Str(loopindex)))
          Next loopindex
          ' creating child nodes under the root
          TreeView1.Nodes(0).Nodes.Add(New TreeNode("Project 6"))
          'creating child nodes under the created child node
          For loopindex As Integer = 1 To 3
              TreeView1.Nodes(0).Nodes(1).Nodes.Add(New  _
                  TreeNode("Project File" &amp; Str(loopindex)))
          Next loopindex
          ' Set the caption bar text of the form.  
          Me.Text = "tutorialspoint.com"
      End Sub
  
      Private Sub openInWeb()
          Try
              Dim url As String = "http://www.stackoverflow.com"
              Process.Start(url)
          Catch ex As Exception
              MsgBox("There's something wrong!")
          Finally
          End Try
      End Sub
  
      Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
          Dim fileReader As System.IO.StreamReader
          fileReader =
          My.Computer.FileSystem.OpenTextFileReader("C:\Users\itpr13266\Desktop\Asnreiu3.txt")
          Dim stringReader As String
          stringReader = fileReader.ReadLine()
          MsgBox("The first line of the file is " &amp; stringReader)
          openInWeb()
      End Sub
  
      Private Sub Button2_Click(sender As System.Object, e As System.EventArgs) Handles Button2.Click
          Dim myStream As Stream = Nothing
          Dim openFileBox As New OpenFileDialog()
  
          openFileBox.InitialDirectory = "c:\"
          openFileBox.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*"
          openFileBox.FilterIndex = 2
          openFileBox.RestoreDirectory = True
  
          If openFileBox.ShowDialog() = System.Windows.Forms.DialogResult.OK Then
              Try
                  myStream = openFileBox.OpenFile()
                  If (myStream IsNot Nothing) Then
                      ' Insert code to read the stream here. 
                      '**************************
                      ' your code will go here  *
                      '**************************
                  End If
              Catch Ex As Exception
                  MessageBox.Show("Cannot read file from disk. Original error: " &amp; Ex.Message)
              Finally
                  If (myStream IsNot Nothing) Then
                      myStream.Close()
                  End If
              End Try
          End If
      End Sub
  
      Private Sub Button3_Click(sender As System.Object, e As System.EventArgs) Handles Button3.Click
          Dim myStream As Stream
          Dim saveFileDialog1 As New SaveFileDialog()
  
          saveFileDialog1.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*"
          saveFileDialog1.FilterIndex = 2
          saveFileDialog1.RestoreDirectory = True
  
          If saveFileDialog1.ShowDialog() = DialogResult.OK Then
              myStream = saveFileDialog1.OpenFile()
              If (myStream IsNot Nothing) Then
                  ' Code to write the stream goes here.
                  myStream.Close()
              End If
          End If
      End Sub
  
      Private Sub ToolTip1_Popup(sender As System.Object, e As System.Windows.Forms.PopupEventArgs) Handles ToolTip1.Popup
  
      End Sub
  
      Private Sub Button(p1 As Object)
          Throw New NotImplementedException
      End Sub
  
      Private Function myButton() As Windows.Forms.Button
          Throw New NotImplementedException
      End Function
  
      Private Sub Button4_Click(sender As System.Object, e As System.EventArgs) Handles Button4.Click
          AboutBox1.Show()
      End Sub
  
      Private Sub Button5_Click(sender As System.Object, e As System.EventArgs) Handles Button5.Click
          Dim lbl As New Label
          lbl.Size = New System.Drawing.Size(159, 23) 'set your size (if required)
          lbl.Location = New System.Drawing.Point(12, 190) 'set your location
          lbl.Text = "You just clicked button 5" 'set the text for your label
          Me.Controls.Add(lbl)  'add your new control to your forms control collection
      End Sub
  
      Public Sub HellowWorld()
          MsgBox("Hello World!")
      End Sub
  
      Private Sub Button6_Click(sender As System.Object, e As System.EventArgs) Handles Button6.Click
          HellowWorld()
      End Sub
  
      Private Sub Button7_Click(sender As System.Object, e As System.EventArgs) Handles Button7.Click
          Dim ProgressBar1 As ProgressBar
          Dim ProgressBar2 As ProgressBar
          ProgressBar1 = New ProgressBar()
          ProgressBar2 = New ProgressBar()
          'set position
          ProgressBar1.Location = New Point(10, 200)
          ProgressBar2.Location = New Point(10, 250)
          'set values
          ProgressBar1.Minimum = 0
          ProgressBar1.Maximum = 200
          ProgressBar1.Value = 130
          ProgressBar2.Minimum = 0
          ProgressBar2.Maximum = 100
          ProgressBar2.Value = 40
          'add the progress bar to the form
          Me.Controls.Add(ProgressBar1)
          Me.Controls.Add(ProgressBar2)
          ' Set the caption bar text of the form.  
      End Sub
  End Class
  </code></pre>