📄 form1.vb
字号:
Public Class Form1
Inherits System.Windows.Forms.Form
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
End Sub
'Form overrides dispose to clean up the component list.
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
'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents MainMenu1 As System.Windows.Forms.MainMenu
Friend WithEvents ContextMenu1 As System.Windows.Forms.ContextMenu
Friend WithEvents MenuItem1 As System.Windows.Forms.MenuItem
Friend WithEvents MenuItem2 As System.Windows.Forms.MenuItem
Friend WithEvents MenuItem4 As System.Windows.Forms.MenuItem
Friend WithEvents MenuItem5 As System.Windows.Forms.MenuItem
Friend WithEvents MenuItem6 As System.Windows.Forms.MenuItem
Friend WithEvents MenuItem7 As System.Windows.Forms.MenuItem
Friend WithEvents MenuItem8 As System.Windows.Forms.MenuItem
Friend WithEvents MenuItem9 As System.Windows.Forms.MenuItem
Friend WithEvents MenuItem3 As System.Windows.Forms.MenuItem
Friend WithEvents Button1 As System.Windows.Forms.Button
Friend WithEvents MenuItem11 As System.Windows.Forms.MenuItem
Friend WithEvents MenuItem12 As System.Windows.Forms.MenuItem
Friend WithEvents MenuItem13 As System.Windows.Forms.MenuItem
Friend WithEvents MenuItem14 As System.Windows.Forms.MenuItem
Friend WithEvents ColorDialog1 As System.Windows.Forms.ColorDialog
Friend WithEvents FontDialog1 As System.Windows.Forms.FontDialog
Friend WithEvents Label1 As System.Windows.Forms.Label
Friend WithEvents changeColor As System.Windows.Forms.MenuItem
Friend WithEvents changeTitleButtonColor As System.Windows.Forms.Button
Friend WithEvents calculateButton As System.Windows.Forms.Button
Friend WithEvents commissionLabel As System.Windows.Forms.Label
Friend WithEvents salesTextBox As System.Windows.Forms.TextBox
Friend WithEvents Label2 As System.Windows.Forms.Label
Friend WithEvents Label3 As System.Windows.Forms.Label
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.MainMenu1 = New System.Windows.Forms.MainMenu
Me.MenuItem1 = New System.Windows.Forms.MenuItem
Me.MenuItem2 = New System.Windows.Forms.MenuItem
Me.MenuItem11 = New System.Windows.Forms.MenuItem
Me.MenuItem12 = New System.Windows.Forms.MenuItem
Me.MenuItem6 = New System.Windows.Forms.MenuItem
Me.MenuItem5 = New System.Windows.Forms.MenuItem
Me.MenuItem4 = New System.Windows.Forms.MenuItem
Me.MenuItem7 = New System.Windows.Forms.MenuItem
Me.MenuItem8 = New System.Windows.Forms.MenuItem
Me.MenuItem9 = New System.Windows.Forms.MenuItem
Me.MenuItem14 = New System.Windows.Forms.MenuItem
Me.MenuItem13 = New System.Windows.Forms.MenuItem
Me.ContextMenu1 = New System.Windows.Forms.ContextMenu
Me.MenuItem3 = New System.Windows.Forms.MenuItem
Me.changeColor = New System.Windows.Forms.MenuItem
Me.Button1 = New System.Windows.Forms.Button
Me.ColorDialog1 = New System.Windows.Forms.ColorDialog
Me.FontDialog1 = New System.Windows.Forms.FontDialog
Me.Label1 = New System.Windows.Forms.Label
Me.changeTitleButtonColor = New System.Windows.Forms.Button
Me.calculateButton = New System.Windows.Forms.Button
Me.commissionLabel = New System.Windows.Forms.Label
Me.salesTextBox = New System.Windows.Forms.TextBox
Me.Label2 = New System.Windows.Forms.Label
Me.Label3 = New System.Windows.Forms.Label
Me.SuspendLayout()
'
'MainMenu1
'
Me.MainMenu1.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.MenuItem1, Me.MenuItem7, Me.MenuItem13})
'
'MenuItem1
'
Me.MenuItem1.Index = 0
Me.MenuItem1.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.MenuItem2, Me.MenuItem6, Me.MenuItem5, Me.MenuItem4})
Me.MenuItem1.Text = "&File"
'
'MenuItem2
'
Me.MenuItem2.Index = 0
Me.MenuItem2.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.MenuItem11, Me.MenuItem12})
Me.MenuItem2.Text = "Open"
'
'MenuItem11
'
Me.MenuItem11.Index = 0
Me.MenuItem11.Text = "Open1"
'
'MenuItem12
'
Me.MenuItem12.Index = 1
Me.MenuItem12.Text = "Open2"
'
'MenuItem6
'
Me.MenuItem6.Index = 1
Me.MenuItem6.Text = "Save"
'
'MenuItem5
'
Me.MenuItem5.Index = 2
Me.MenuItem5.Text = "-"
'
'MenuItem4
'
Me.MenuItem4.Index = 3
Me.MenuItem4.Shortcut = System.Windows.Forms.Shortcut.CtrlX
Me.MenuItem4.Text = "e&xit"
'
'MenuItem7
'
Me.MenuItem7.Index = 1
Me.MenuItem7.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.MenuItem8, Me.MenuItem9, Me.MenuItem14})
Me.MenuItem7.Text = "Setting"
'
'MenuItem8
'
Me.MenuItem8.Index = 0
Me.MenuItem8.Text = "SetLabelColor"
'
'MenuItem9
'
Me.MenuItem9.Index = 1
Me.MenuItem9.Text = "SetLabelFont"
'
'MenuItem14
'
Me.MenuItem14.Index = 2
Me.MenuItem14.Text = ""
'
'MenuItem13
'
Me.MenuItem13.Index = 2
Me.MenuItem13.Text = ""
'
'ContextMenu1
'
Me.ContextMenu1.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.MenuItem3, Me.changeColor})
'
'MenuItem3
'
Me.MenuItem3.Index = 0
Me.MenuItem3.Text = "Close"
'
'changeColor
'
Me.changeColor.Index = 1
Me.changeColor.Text = "changeColor"
'
'Button1
'
Me.Button1.ContextMenu = Me.ContextMenu1
Me.Button1.Location = New System.Drawing.Point(120, 88)
Me.Button1.Name = "Button1"
Me.Button1.Size = New System.Drawing.Size(184, 32)
Me.Button1.TabIndex = 0
Me.Button1.Text = "Show ContextMenu"
'
'Label1
'
Me.Label1.Location = New System.Drawing.Point(160, 40)
Me.Label1.Name = "Label1"
Me.Label1.Size = New System.Drawing.Size(96, 24)
Me.Label1.TabIndex = 1
Me.Label1.Text = "Label1"
'
'changeTitleButtonColor
'
Me.changeTitleButtonColor.Location = New System.Drawing.Point(144, 192)
Me.changeTitleButtonColor.Name = "changeTitleButtonColor"
Me.changeTitleButtonColor.Size = New System.Drawing.Size(144, 40)
Me.changeTitleButtonColor.TabIndex = 2
Me.changeTitleButtonColor.Text = "changeTitleButtonColor"
'
'calculateButton
'
Me.calculateButton.Location = New System.Drawing.Point(104, 320)
Me.calculateButton.Name = "calculateButton"
Me.calculateButton.Size = New System.Drawing.Size(88, 23)
Me.calculateButton.TabIndex = 3
Me.calculateButton.Text = "calculate"
'
'commissionLabel
'
Me.commissionLabel.Location = New System.Drawing.Point(272, 320)
Me.commissionLabel.Name = "commissionLabel"
Me.commissionLabel.Size = New System.Drawing.Size(104, 24)
Me.commissionLabel.TabIndex = 4
Me.commissionLabel.Text = "commissionLabel"
'
'salesTextBox
'
Me.salesTextBox.Location = New System.Drawing.Point(168, 264)
Me.salesTextBox.Name = "salesTextBox"
Me.salesTextBox.TabIndex = 5
Me.salesTextBox.Text = ""
'
'Label2
'
Me.Label2.Location = New System.Drawing.Point(72, 264)
Me.Label2.Name = "Label2"
Me.Label2.Size = New System.Drawing.Size(72, 23)
Me.Label2.TabIndex = 6
Me.Label2.Text = "Sales Amount"
'
'Label3
'
Me.Label3.BackColor = System.Drawing.Color.Red
Me.Label3.ForeColor = System.Drawing.Color.Red
Me.Label3.Location = New System.Drawing.Point(0, 152)
Me.Label3.Name = "Label3"
Me.Label3.Size = New System.Drawing.Size(440, 2)
Me.Label3.TabIndex = 7
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 15)
Me.ClientSize = New System.Drawing.Size(440, 385)
Me.ContextMenu = Me.ContextMenu1
Me.Controls.Add(Me.Label3)
Me.Controls.Add(Me.Label2)
Me.Controls.Add(Me.salesTextBox)
Me.Controls.Add(Me.commissionLabel)
Me.Controls.Add(Me.calculateButton)
Me.Controls.Add(Me.changeTitleButtonColor)
Me.Controls.Add(Me.Label1)
Me.Controls.Add(Me.Button1)
Me.Menu = Me.MainMenu1
Me.Name = "Form1"
Me.Text = "Form1"
Me.ResumeLayout(False)
End Sub
#End Region
Private Sub MenuItem4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles MenuItem4.Click, MenuItem3.Click
Me.Close()
End Sub
Private Sub MenuItem8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles MenuItem8.Click, changeColor.Click
ColorDialog1.ShowDialog()
Label1.ForeColor = ColorDialog1.Color
End Sub
Private Sub MenuItem9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem9.Click
FontDialog1.ShowDialog()
Label1.Font = FontDialog1.Font
End Sub
' use PROCEDURE & FUNCTION
Private Sub SelectColor(ByVal incomingColor As Color)
With ColorDialog1
.Color = incomingColor
.ShowDialog()
End With
End Sub
Private Sub changeTitleButtonColor_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles changeTitleButtonColor.Click
Dim originalColor As Color
originalColor = Label1.ForeColor
SelectColor(originalColor)
Label1.ForeColor = ColorDialog1.Color
End Sub
Private Function Commission(ByVal salesAmountDecimal As Decimal) As Decimal
If salesAmountDecimal < 100D Then
Commission = 0D
Else
Commission = 0.15 * salesAmountDecimal
End If
End Function
Private Sub calculateButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles calculateButton.Click
Dim salesDecimal As Decimal
salesDecimal = Decimal.Parse(salesTextBox.Text)
commissionLabel.Text = Commission(salesDecimal.ToString("C"))
End Sub
End Class
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -