Advance Message box is used whether the user want to perform an action or not. This kind of message box is good for deleting or closing applications in visual basic.net.
With the combination of "If Statement" we can summon the message box to appear and ask the user to perform an action..
Here is the sample code in using this message box with if statement.
Try to make a new project and add this code to form1_mouseclick event, the run it and click anywhere inside the form.. then see what is the result after clicking the "Yes" and "No" Buttons on the message box.
If MessageBox.Show("Is the name if the form = form1?", "Question", MessageBoxButtons.YesNo) = Windows.Forms.DialogResult.Yes Then
MsgBox("The name of the form is form1", MsgBoxStyle.Information, "Correct")
ElseMsgBox("the name of the form is not form1", MsgBoxStyle.Critical, "Wrong")End If
From the code above, we can see that the message box contains a question about what is the name of the form.
Logic: when form1 is clicked
The Question message box will appear and it will contain a question as shown in the code above.
If the user click the "Yes" Button another message box will appear that contains the answer.
If the user click the "No" button a message box will appear that will say that the name of the form is not equal to "form1"
Go ahead try this code on your program, you can add this code on button1_click event to do some action.. you will just need to change the logic or the content of the message box on your source code.. Just experiment using this code and this will make your program a bit more exciting to use and you can see the interaction of your program with the user.
Watch Video Tutorial
No comments:
Post a Comment