Public Class Form1Class Form1
Private Sub Form1_Load()Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'加按钮
Dim bt1 As New Button
bt1.Text = "TestButton"
bt1.Left = 100
bt1.Top = 100
bt1.Width = 100
bt1.Height = 30
Me.Controls.Add(bt1)
bt1.Show()
AddHandler bt1.Click, AddressOf ClickHandler'给按钮加事件,同样适用于其它控件
'bt1.PerformClick() '自动点击按钮
'加工具栏
Dim ts As New ToolStrip
ts.Items.Add("Test03")
ts.Items.Add("Test04", Nothing, New EventHandler(AddressOf windowNewToolStrip_Click))
ts.Dock = DockStyle.Top
Me.Controls.Add(ts)
'加菜单
Dim ms As New MenuStrip()
Dim windowMenu As New ToolStripMenuItem("MainMenu-1")
Dim windowNewMenu As New ToolStripMenuItem("SubMenu-1.1", Nothing, New EventHandler(AddressOf windowNewMenu_Click))
windowMenu.DropDownItems.Add(windowNewMenu)
CType(windowMenu.DropDown, ToolStripDropDownMenu).ShowImageMargin = False
CType(windowMenu.DropDown, ToolStripDropDownMenu).ShowCheckMargin = True
' Assign the ToolStripMenuItem that displays
' the list of child forms.
ms.MdiWindowListItem = windowMenu
' Add the window ToolStripMenuItem to the MenuStrip.
ms.Items.Add(windowMenu)
' Dock the MenuStrip to the top of the form.
ms.Dock = DockStyle.Top
' The Form.MainMenuStrip property determines the merge target.
Me.MainMenuStrip = ms
Me.Controls.Add(ms)
'加状态栏
Dim sb As New StatusBar
sb.Dock = DockStyle.Bottom
Dim panel1 As New StatusBarPanel
Dim panel2 As New StatusBarPanel
' Set the width of panel2 explicitly and set
' panel1 to fill in the remaining space.
panel2.Width = 80
panel1.AutoSize = StatusBarPanelAutoSize.Spring
' Set the text alignment within each panel.
panel1.Alignment = HorizontalAlignment.Left
panel2.Alignment = HorizontalAlignment.Right
' Display the first panel without a border and the second
' with a raised border.
panel1.BorderStyle = StatusBarPanelBorderStyle.Sunken
panel2.BorderStyle = StatusBarPanelBorderStyle.Raised
' Set the text of the panels. The panel1 object is reserved
' for line numbers, while panel2 is set to the current time.
panel1.Text = "Reserved for important information."
panel2.Text = System.DateTime.Now.ToShortTimeString
' Set a tooltip for panel2
panel2.ToolTipText = "Click time to display seconds"
' Display panels in statusBar1 and add them to the
' status bar's StatusBarPanelCollection.
sb.ShowPanels = True
sb.Panels.Add(panel1)
sb.Panels.Add(panel2)
Me.Controls.Add(sb)
End Sub
Private Sub ClickHandler()Sub ClickHandler(ByVal sender As Object, ByVal e As System.EventArgs)
MsgBox("Just a ButtonTest")
End Sub
Private Sub windowNewToolStrip_Click()Sub windowNewToolStrip_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
MsgBox("Just a ToolStripTest")
End Sub
Private Sub windowNewMenu_Click()Sub windowNewMenu_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
MsgBox("Just a MenuStripTest")
End Sub
Private Sub sb_PanelClick()Sub sb_PanelClick(ByVal sender As Object, ByVal e As StatusBarPanelClickEventArgs)
MsgBox("Just a StatusBar")
End Sub
End Class
Private Sub Form1_Load()Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'加按钮
Dim bt1 As New Button
bt1.Text = "TestButton"
bt1.Left = 100
bt1.Top = 100
bt1.Width = 100
bt1.Height = 30
Me.Controls.Add(bt1)
bt1.Show()
AddHandler bt1.Click, AddressOf ClickHandler'给按钮加事件,同样适用于其它控件
'bt1.PerformClick() '自动点击按钮
'加工具栏
Dim ts As New ToolStrip
ts.Items.Add("Test03")
ts.Items.Add("Test04", Nothing, New EventHandler(AddressOf windowNewToolStrip_Click))
ts.Dock = DockStyle.Top
Me.Controls.Add(ts)
'加菜单
Dim ms As New MenuStrip()
Dim windowMenu As New ToolStripMenuItem("MainMenu-1")
Dim windowNewMenu As New ToolStripMenuItem("SubMenu-1.1", Nothing, New EventHandler(AddressOf windowNewMenu_Click))
windowMenu.DropDownItems.Add(windowNewMenu)
CType(windowMenu.DropDown, ToolStripDropDownMenu).ShowImageMargin = False
CType(windowMenu.DropDown, ToolStripDropDownMenu).ShowCheckMargin = True
' Assign the ToolStripMenuItem that displays
' the list of child forms.
ms.MdiWindowListItem = windowMenu
' Add the window ToolStripMenuItem to the MenuStrip.
ms.Items.Add(windowMenu)
' Dock the MenuStrip to the top of the form.
ms.Dock = DockStyle.Top
' The Form.MainMenuStrip property determines the merge target.
Me.MainMenuStrip = ms
Me.Controls.Add(ms)
'加状态栏
Dim sb As New StatusBar
sb.Dock = DockStyle.Bottom
Dim panel1 As New StatusBarPanel
Dim panel2 As New StatusBarPanel
' Set the width of panel2 explicitly and set
' panel1 to fill in the remaining space.
panel2.Width = 80
panel1.AutoSize = StatusBarPanelAutoSize.Spring
' Set the text alignment within each panel.
panel1.Alignment = HorizontalAlignment.Left
panel2.Alignment = HorizontalAlignment.Right
' Display the first panel without a border and the second
' with a raised border.
panel1.BorderStyle = StatusBarPanelBorderStyle.Sunken
panel2.BorderStyle = StatusBarPanelBorderStyle.Raised
' Set the text of the panels. The panel1 object is reserved
' for line numbers, while panel2 is set to the current time.
panel1.Text = "Reserved for important information."
panel2.Text = System.DateTime.Now.ToShortTimeString
' Set a tooltip for panel2
panel2.ToolTipText = "Click time to display seconds"
' Display panels in statusBar1 and add them to the
' status bar's StatusBarPanelCollection.
sb.ShowPanels = True
sb.Panels.Add(panel1)
sb.Panels.Add(panel2)
Me.Controls.Add(sb)
End Sub
Private Sub ClickHandler()Sub ClickHandler(ByVal sender As Object, ByVal e As System.EventArgs)
MsgBox("Just a ButtonTest")
End Sub
Private Sub windowNewToolStrip_Click()Sub windowNewToolStrip_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
MsgBox("Just a ToolStripTest")
End Sub
Private Sub windowNewMenu_Click()Sub windowNewMenu_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
MsgBox("Just a MenuStripTest")
End Sub
Private Sub sb_PanelClick()Sub sb_PanelClick(ByVal sender As Object, ByVal e As StatusBarPanelClickEventArgs)
MsgBox("Just a StatusBar")
End Sub
End Class