对所有人来说,美好的一天,我的msgbox提示用vbyesnocancel时遇到了一些麻烦
•此代码一切正常工作“但是”我需要点击多个是,否,取消激活其功能
Private Sub cbEnableDeductions_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cbEnableDeductions.Click
If MsgBox("Do You want To Enable deductions?", vbYesNoCancel) = MsgBoxResult.Yes Then
cbEnableDeductions.Checked = True
txtSSS.Enabled = True
txtHDMF.Enabled = True
txtPhilHealth.Enabled = True
ElseIf MsgBox("Do You want To Enable deductions?", vbYesNoCancel) = MsgBoxResult.No Then
cbEnableDeductions.Checked = True
Total()
ElseIf MsgBox("Do You want To Enable deductions?", vbYesNoCancel) = MsgBoxResult.Cancel Then
cbEnableDeductions.CheckState = False
End If
End Sub
•使用此代码“NO”和“CANCEL”功能无效
Private Sub cbEnableDeductions_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cbEnableDeductions.Click
If MsgBox("Do You want To Enable deductions?", vbYesNoCancel) = MsgBoxResult.Yes Then
cbEnableDeductions.Checked = True
txtSSS.Enabled = True
txtHDMF.Enabled = True
txtPhilHealth.Enabled = True
ElseIf vbYesNoCancel = MsgBoxResult.No Then
cbEnableDeductions.Checked = True
Total()
ElseIf vbYesNoCancel = MsgBoxResult.Cancel Then
cbEnableDeductions.CheckState = False
End If
End Sub
答案 0 :(得分:1)
试试这个,你用你现有的代码询问输入3次。
Dim result As MsgBoxResult = MsgBox("Do You want To Enable deductions?", vbYesNoCancel)
If result = MsgBoxResult.Yes Then
cbEnableDeductions.Checked = True
txtSSS.Enabled = True
txtHDMF.Enabled = True
txtPhilHealth.Enabled = True
ElseIf result = MsgBoxResult.No Then
cbEnableDeductions.Checked = True
Total()
ElseIf result = MsgBoxResult.Cancel Then
cbEnableDeductions.CheckState = False
End If
或者您可以使用CASE
Select Case MsgBox("Do You want To Enable deductions?", vbYesNoCancel)
Case MsgBoxResult.Yes
cbEnableDeductions.Checked = True
txtSSS.Enabled = True
txtHDMF.Enabled = True
txtPhilHealth.Enabled = True
Case MsgBoxResult.No
cbEnableDeductions.Checked = True
Total()
Case MsgBoxResult.Cancel
cbEnableDeductions.CheckState = False
End Select
答案 1 :(得分:1)
尝试这样的事情:
Private Sub cbEnableDeductions_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cbEnableDeductions.Click
Dim msgBoxResult = MsgBox("Do You want To Enable deductions?", vbYesNoCancel)
If msgBoxResult = MsgBoxResult.Yes Then
cbEnableDeductions.Checked = True
txtSSS.Enabled = True
txtHDMF.Enabled = True
xtPhilHealth.Enabled = True
ElseIf msgBoxResult = MsgBoxResult.No Then
cbEnableDeductions.Checked = True
Total()
ElseIf msgBoxResult = MsgBoxResult.Cancel Then
cbEnableDeductions.CheckState = False
End If
End Sub