In the illustration below, the prompt is "Press to change to red". The title is "RED".
Message Box

Modify the previous code as shown below:

Private Sub BtnHello_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _ 
    Handles BtnHello.Click
  MsgBox("Press to change to red", MsgBoxStyle.OkOnly, "RED")
  Me.BackColor = Color.Red
End Sub 'BtnHello_Click

As soon as the user presses OK, the message box disappears and the form turns red.

In the next example the user is given a choice. Since we do not know which button they will press, we will use a function so we can look at the answer.
The format for the function is:
<answer> = msgBox( <prompt>,<type>,<title>)

MessageBox

We will turn the form red only if the press Yes.

Notice that as you type the code most of the choices are selected from pop-up boxes.
Private Sub BtnHello_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _
    Handles BtnHello.Click
  Dim Answer As MsgBoxResult
  Answer = MsgBox("Do you like red?", MsgBoxStyle.YesNo, "Color")
  If Answer = MsgBoxResult.Yes Then
     Me.BackColor = Color.Red
  End If
End Sub 'BtnHello_Click

Experiment:
Once the user press yes, the button does not have any affect. If they click No generate a color with red = 0 and random values for green and blue.
INDEX, Text Boxes, Input Boxes, Message Boxes, More Message Boxes, Dialog Boxes, Open File Dialog
Next lesson: Loops in Visual Basic

Copyright © Zebra0.com
All rights reserved worldwide.

 
 

Message Boxes