在Visual Studio 2010中的Visual Basic中,如果用于提供消息,
MsgBox("hello", 4, "status")
如何操作msgbox中的结果是或否?
如果用户提供否,就会发生这种情况,如果否,就会发生这种情况。
答案 0 :(得分:8)
您需要检查MsgBox
是否返回vbYes
。
例如:
If vbYes = MsgBox("hello", vbYesNo, "status") Then
'Do things
Else
'Don't do things
End If
答案 1 :(得分:2)
MsgBox Function (Visual Basic)
Lesson 10: Introduction to VB Built-in Functions
示例代码:
Private Sub Test_Click()
Dim testMsg As Integer
testMsg = MsgBox("Click to test", 1, "Test message")
If testMsg = 1 Then 'User clicked on OK button
Display.Caption = "Test Succeeded"
Else 'User clicked on Cancel button
Display.Caption = "Test failed"
End If
End Sub
答案 2 :(得分:0)
非常确定你也可以这样做:
Dim response As MsgBoxResult = MsgBox("Are You Sure you want to delete this entry?", MsgBoxStyle.DefaultButton2 Or MsgBoxStyle.YesNo Or MsgBoxStyle.Critical, "Warning")
If response = MsgBoxResult.Yes Then