This should get you sparking in the right direction at run time.....
Imports System.Drawing
Public Class ToolBox
Dim btn As Control
Dim singleBtnHeight As Integer
Dim FormWidth As Integer = 636
Private Sub AddNewButtonToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles AddNewButtonToolStripMenuItem.Click
singleBtnHeight = 26
Dim newButton As New Button
With newButton
.Text = "Left Click to remove me! "
.Name = "btnClickRemove"
Dim i As Integer = Me.Controls.Count - 1
.Size = New Size(Me.Controls(i).ClientRectangle.Width, singleBtnHeight)
.Dock = DockStyle.Bottom
End With
Me.ClientSize = New Size(FormWidth, (Me.ClientSize.Height + singleBtnHeight))
Me.Controls.Add(newButton)
AddHandler newButton.Click, AddressOf New_Button_Click
newButton = Nothing
End Sub
Private Sub New_Button_Click(sender As Object, e As MouseEventArgs)
singleBtnHeight = 26
If e.Button = Windows.Forms.MouseButtons.Left Then
btn = sender
If MessageBox.Show("Remove Button?", "", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = Windows.Forms.DialogResult.Yes Then
Me.Controls.Remove(btn)
Dim x As Integer = FormWidth
Dim y As Integer = Me.ClientSize.Height - singleBtnHeight
Me.ClientSize = New Size(x, y)
x = Nothing
y = Nothing
singleBtnHeight = Nothing
End If
End If
End Sub
End Class