frmclass.vb
来自「Programming Web and Desktop Applications」· VB 代码 · 共 559 行 · 第 1/2 页
VB
559 行
'
'chkContract
'
Me.chkContract.ForeColor = System.Drawing.SystemColors.ControlText
Me.chkContract.Location = New System.Drawing.Point(16, 40)
Me.chkContract.Name = "chkContract"
Me.chkContract.Size = New System.Drawing.Size(184, 24)
Me.chkContract.TabIndex = 0
Me.chkContract.Text = "Contract Employee?"
'
'GroupBox3
'
Me.GroupBox3.Controls.AddRange(New System.Windows.Forms.Control() {Me.chkNonManager, Me.txtNonManagerHours, Me.txtBonus, Me.txtSalary, Me.lblNonManagerHours, Me.lblBonus, Me.lblSalary})
Me.GroupBox3.Font = New System.Drawing.Font("Arial", 7.8!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.GroupBox3.ForeColor = System.Drawing.Color.Red
Me.GroupBox3.Location = New System.Drawing.Point(32, 448)
Me.GroupBox3.Name = "GroupBox3"
Me.GroupBox3.Size = New System.Drawing.Size(448, 104)
Me.GroupBox3.TabIndex = 2
Me.GroupBox3.TabStop = False
Me.GroupBox3.Text = "Salary Information"
'
'chkNonManager
'
Me.chkNonManager.ForeColor = System.Drawing.SystemColors.ControlText
Me.chkNonManager.Location = New System.Drawing.Point(40, 64)
Me.chkNonManager.Name = "chkNonManager"
Me.chkNonManager.Size = New System.Drawing.Size(152, 24)
Me.chkNonManager.TabIndex = 6
Me.chkNonManager.Text = "Non-Manager?"
'
'txtNonManagerHours
'
Me.txtNonManagerHours.ForeColor = System.Drawing.SystemColors.ControlText
Me.txtNonManagerHours.Location = New System.Drawing.Point(336, 64)
Me.txtNonManagerHours.Name = "txtNonManagerHours"
Me.txtNonManagerHours.Size = New System.Drawing.Size(72, 22)
Me.txtNonManagerHours.TabIndex = 5
Me.txtNonManagerHours.Text = "40"
Me.txtNonManagerHours.Visible = False
'
'txtBonus
'
Me.txtBonus.ForeColor = System.Drawing.SystemColors.ControlText
Me.txtBonus.Location = New System.Drawing.Point(336, 32)
Me.txtBonus.Name = "txtBonus"
Me.txtBonus.Size = New System.Drawing.Size(72, 22)
Me.txtBonus.TabIndex = 4
Me.txtBonus.Text = ""
'
'txtSalary
'
Me.txtSalary.ForeColor = System.Drawing.SystemColors.ControlText
Me.txtSalary.Location = New System.Drawing.Point(96, 32)
Me.txtSalary.Name = "txtSalary"
Me.txtSalary.Size = New System.Drawing.Size(104, 22)
Me.txtSalary.TabIndex = 3
Me.txtSalary.Text = ""
'
'lblNonManagerHours
'
Me.lblNonManagerHours.ForeColor = System.Drawing.SystemColors.ControlText
Me.lblNonManagerHours.Location = New System.Drawing.Point(240, 64)
Me.lblNonManagerHours.Name = "lblNonManagerHours"
Me.lblNonManagerHours.Size = New System.Drawing.Size(88, 16)
Me.lblNonManagerHours.TabIndex = 2
Me.lblNonManagerHours.Text = "Hours/Week"
Me.lblNonManagerHours.TextAlign = System.Drawing.ContentAlignment.MiddleRight
Me.lblNonManagerHours.Visible = False
'
'lblBonus
'
Me.lblBonus.ForeColor = System.Drawing.SystemColors.ControlText
Me.lblBonus.Location = New System.Drawing.Point(256, 32)
Me.lblBonus.Name = "lblBonus"
Me.lblBonus.Size = New System.Drawing.Size(72, 16)
Me.lblBonus.TabIndex = 1
Me.lblBonus.Text = "Bonus"
Me.lblBonus.TextAlign = System.Drawing.ContentAlignment.MiddleRight
'
'lblSalary
'
Me.lblSalary.ForeColor = System.Drawing.SystemColors.ControlText
Me.lblSalary.Location = New System.Drawing.Point(16, 32)
Me.lblSalary.Name = "lblSalary"
Me.lblSalary.Size = New System.Drawing.Size(64, 16)
Me.lblSalary.TabIndex = 0
Me.lblSalary.Text = "Salary"
Me.lblSalary.TextAlign = System.Drawing.ContentAlignment.MiddleRight
'
'btnCompute
'
Me.btnCompute.BackColor = System.Drawing.SystemColors.Control
Me.btnCompute.Font = New System.Drawing.Font("Arial", 7.8!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.btnCompute.Location = New System.Drawing.Point(32, 400)
Me.btnCompute.Name = "btnCompute"
Me.btnCompute.Size = New System.Drawing.Size(144, 32)
Me.btnCompute.TabIndex = 3
Me.btnCompute.Text = "&Compute Pay"
'
'btnClear
'
Me.btnClear.BackColor = System.Drawing.SystemColors.Control
Me.btnClear.Font = New System.Drawing.Font("Arial", 7.8!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.btnClear.Location = New System.Drawing.Point(192, 400)
Me.btnClear.Name = "btnClear"
Me.btnClear.Size = New System.Drawing.Size(136, 32)
Me.btnClear.TabIndex = 4
Me.btnClear.Text = "C&lear"
'
'btnExit
'
Me.btnExit.BackColor = System.Drawing.SystemColors.Control
Me.btnExit.Font = New System.Drawing.Font("Arial", 7.8!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.btnExit.Location = New System.Drawing.Point(344, 400)
Me.btnExit.Name = "btnExit"
Me.btnExit.Size = New System.Drawing.Size(136, 32)
Me.btnExit.TabIndex = 5
Me.btnExit.Text = "E&xit"
'
'Label12
'
Me.Label12.Font = New System.Drawing.Font("Arial", 12.0!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.Label12.Location = New System.Drawing.Point(88, 576)
Me.Label12.Name = "Label12"
Me.Label12.Size = New System.Drawing.Size(152, 24)
Me.Label12.TabIndex = 6
Me.Label12.Text = "Compensation"
'
'lblCompensation
'
Me.lblCompensation.Font = New System.Drawing.Font("Arial", 12.0!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.lblCompensation.Location = New System.Drawing.Point(272, 576)
Me.lblCompensation.Name = "lblCompensation"
Me.lblCompensation.Size = New System.Drawing.Size(136, 24)
Me.lblCompensation.TabIndex = 7
'
'frmClass
'
Me.AutoScaleBaseSize = New System.Drawing.Size(6, 15)
Me.ClientSize = New System.Drawing.Size(512, 624)
Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.lblCompensation, Me.Label12, Me.btnExit, Me.btnClear, Me.btnCompute, Me.GroupBox3, Me.GroupBox2, Me.GroupBox1})
Me.Name = "frmClass"
Me.Text = "Class Example"
Me.GroupBox1.ResumeLayout(False)
Me.GroupBox2.ResumeLayout(False)
Me.GroupBox3.ResumeLayout(False)
Me.ResumeLayout(False)
End Sub
#End Region
Private WithEvents objCoEmployee As ContractEmployee
Private WithEvents objFTEmployee As FullTimeEmployee
Private mstrErr As Boolean
Private Sub objCoEmployee_ErrorEvent(ByVal strObj As String) Handles objCoEmployee.ErrorEvent, objFTEmployee.ErrorEvent
'This handles the errors raised by the object
MessageBox.Show(strObj & " incorrect")
mstrErr = True
End Sub
Private Sub btnCompute_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCompute.Click
Dim strSSN As String = txtSSN.Text
Dim strLastName As String = txtLastName.Text
Dim strFirstName As String = txtFirstName.Text
Dim strAddress As String = txtAddress.Text
Dim intAge As Integer = CInt(txtAge.Text)
Dim intRank As Integer = CInt(txtRank.Text)
If chkContract.Checked Then
'Instantiate ContractEmployee Class
objCoEmployee = New ContractEmployee()
objCoEmployee.SSN = strSSN
objCoEmployee.LastName = strLastName
objCoEmployee.FirstName = strFirstName
objCoEmployee.Age = intAge
objCoEmployee.Rank = intRank
If mstrErr = False Then
objCoEmployee.Hours = CInt(txtHours.Text)
objCoEmployee.PayRate = CSng(txtRate.Text)
'Finally Compute Compensation
lblCompensation.Text = FormatCurrency(objCoEmployee.Compensation)
End If
objCoEmployee = Nothing
mstrErr = False
Else
objFTEmployee = New FullTimeEmployee(CInt(txtNonManagerHours.Text))
objFTEmployee.SSN = strSSN
objFTEmployee.LastName = strLastName
objFTEmployee.FirstName = strFirstName
objFTEmployee.Age = intAge
objFTEmployee.Rank = intRank
If mstrErr = False Then
objFTEmployee.Salary = CSng(txtSalary.Text)
objFTEmployee.Bonus = CSng(txtBonus.Text)
lblCompensation.Text = FormatCurrency(objFTEmployee.Compensation)
End If
objFTEmployee = Nothing
mstrErr = False
End If
End Sub
Private Sub chkContract_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chkContract.CheckedChanged
'Make controls visible/Invisible based on checkbox state
If chkContract.Checked Then
lblRate.Visible = True
lblHours.Visible = True
txtRate.Visible = True
txtHours.Visible = True
chkNonManager.Visible = False
txtSalary.Visible = False
txtBonus.Visible = False
lblBonus.Visible = False
lblSalary.Visible = False
Else
lblRate.Visible = False
lblHours.Visible = False
txtRate.Visible = False
txtHours.Visible = False
chkNonManager.Visible = True
txtSalary.Visible = True
txtBonus.Visible = True
lblBonus.Visible = True
lblSalary.Visible = True
End If
End Sub
Private Sub chkNonManager_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chkNonManager.CheckedChanged
'Make controls visible/Invisible based on checkbox state
If chkNonManager.Checked Then
txtNonManagerHours.Visible = True
lblNonManagerHours.Visible = True
chkContract.Visible = False
Else
txtNonManagerHours.Visible = False
lblNonManagerHours.Visible = False
chkContract.Visible = True
End If
txtNonManagerHours.Text = CStr(40)
End Sub
Private Sub btnClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClear.Click
'Clear controls to their default state
txtSSN.Text = ""
txtLastName.Text = ""
txtFirstName.Text = ""
txtAge.Text = ""
txtAddress.Text = ""
txtRank.Text = ""
chkContract.Checked = False
txtRate.Text = ""
txtHours.Text = ""
lblCompensation.Text = ""
chkNonManager.Visible = True
chkNonManager.Checked = False
txtNonManagerHours.Text = CStr(40)
txtBonus.Text = ""
txtSalary.Text = ""
txtSSN.Focus()
End Sub
Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click
'Terminate the Project
End
End Sub
End Class
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?