Message Box and Input Box
Message Box and Input Box
Message Box and Input Box
MessageBox Class
• .NET has introduced a class called MessageBox which
encapsulates all the features of MsgBox.
• The difference between MsgBox and MessageBox is that
Msgbox is a function while MessageBox is a class.
• The MessageBox class has various overloaded Show
methods for different parameters.
• From a practical standpoint, both the MsgBox function and
the MessageBox class will accomplish the same thing.
• The arguments for MessageBox are specified in a slightly
different order from MsgBox.
• MessageBox.Show Method
• To show the message box we need to call the Show
method of the MessageBox class, for example:
-MessageBox.Show("Hello World!")
Displaying Message Boxes
• Use Message box to
– Display message
– Get response
• Message Box class
– Member of System.Windows.Forms namespace
– Single method named Show
• Creates instance of MessageBox
• Makes it visible
Displaying Message Boxes (Contd..)
• Show() method arguments
– Message to display
• Can string literal or variable
– Caption to display
– Buttons to display
MessageBoxIcon.Question
MessageBoxIcon.Exclamatio
n
- or -
MessageBoxIcon.Warning
MessageBoxIcon.Asterisk
- or -
MessageBoxIcon.Informatio
n
(none)
MessageBoxIcon.None
Value Description
DialogResult.OK The OK button was pressed
DialogResult.Cancel The Cancel button was pressed
DialogResult.Abort The Abort button was pressed
DialogResult.Retry The Retry button was pressed
DialogResult.Ignore The Ignore button was pressed
DialogResult.Yes The Yes button was pressed
DialogResult.No The No button was pressed
DialogResult.None Nothing is returned from the dialog
box. This means that the modal dialog
continues running.
Input Box
• Usually, a text box is used to obtain input
described by a label. Sometimes we want just
one piece of input and would rather not have
a text box and label stay on the screen forever.
The problem can be solved with an input box,
which is an input form automatically created
by VB for you.
InputBox( ) function
• An InputBox( ) function will display a message box where the user
can enter a value or a message in the form of text.
• Syntax
– myMessage=InputBox(Prompt, Title, default_text, x-position, y-
position)
• myMessage is a string type but which accept the message input by
the users. The arguments are explained as follows:
• Prompt - The message displayed normally as a question asked.
• Title - The title of the Input Box.
• default-text - The default text that appears in the input field where
users can use it as his intended input or he may change to the
message he wish to enter.
• x-position and y-position - the position or the coordinates of the
input box.
Input Box Example
• Private Sub Button1_Click(ByVal sender As
System.Object, ByVal e As System.EventArgs)
Handles Button7.Click
• Dim r As String
• r = InputBox("hi", "demo", "fun", 50, 70)
• End Sub