Technical Training
VB.NET 2005MessageBox class Parameters
Application Class and Message Class
The following example shows how to ask the user a Yes or No question and make a decision based on the response
Private Sub ValidateUserEntry()
'Checks the value of the text.The above example also shows that we can take a response from the message box and use the value of the result to perform specific actions.
If ServerName.Text.Length = 0 Then
'Initializes variables to pass to the MessageBox.Show method.
Dim Message As String
Dim Caption As String
Dim Buttons As MessageBoxButtons
Dim Result As DialogResult
Message = "You did not enter a server name. Cancel this operation?"
Caption = "No Server Name Specified"
Buttons = MessageBoxButtons.YesNo
'Displays the MessageBox
Result = MessageBox.Show(Me, Message, Caption, Buttons)
'Gets the result of the MessageBox display.
If Result = DialogResult.Yes Then
'Closes the parent form.
Me.Close()
End If
End If
End Sub
Visual Basic has a public function MsgBox. It displays a message in a dialog box, waits for the user to click a button, and then returns an integer indicating which button the user clicked.
Public Function MsgBox( _
ByVal Prompt As Object, _
Optional ByVal Buttons As MsgBoxStyle = MsgBoxStyle.OKOnly, _
Optional ByVal Title As Object = Nothing _
) As MsgBoxResult
MessageBox class Parameters
Prompt
Required. String expression displayed as the message in the dialog box. The maximum length of Prompt is approximately 1024 characters, depending on the width of the characters used. If Prompt has more than one line, you can separate the lines using a carriage return character, a linefeed character, or a carriage return/linefeed character combination between each line.
Buttons
Optional. Numeric expression that is the sum of values specifying the number and type of buttons to display, the icon style to use, the identity of the default button, and the modality of the message box. If you omit Buttons, the default value is zero.
Title
Optional. String expression displayed in the title bar of the dialog box. If you omit Title, the application name is placed in the title bar.
Settings
The MsgBoxStyle enumeration values are listed in the following table.
|
Enumeration |
Value |
Description |
|
OKOnly |
0 |
Displays OK button only. |
|
OKCancel |
1 |
Displays OK and Cancel buttons. |
|
AbortRetryIgnore |
2 |
Displays Abort, Retry, and Ignore buttons. |
|
YesNoCancel |
3 |
Displays Yes, No, and Cancel buttons. |
|
YesNo |
4 |
Displays Yes and No buttons. |
|
RetryCancel |
5 |
Displays Retry and Cancel buttons. |
|
Critical |
16 |
Displays Critical Message icon. |
|
Question |
32 |
Displays Warning Query icon. |
|
Exclamation |
48 |
Displays Warning Message icon. |
|
Information |
64 |
Displays Information Message icon. |
|
DefaultButton1 |
0 |
First button is default. |
|
DefaultButton2 |
256 |
Second button is default. |
|
DefaultButton3 |
512 |
Third button is default. |
|
ApplicationModal |
0 |
Application is modal. The user must respond to the message box before continuing work in the current application. |
|
SystemModal |
4096 |
System is modal. All applications are suspended until the user responds to the message box. |
|
MsgBoxSetForeground |
65536 |
Specifies the message box window as the foreground window. |
|
MsgBoxRight |
524288 |
Text is right-aligned. |
|
MsgBoxRtlReading |
1048576 |
Specifies text should appear as right-to-left reading on Hebrew and Arabic systems. |
{mosgoogle center}
The first group of values (0–5) describes the number and type of buttons displayed in the dialog box; the second group (16, 32, 48, 64) describes the icon style; the third group (0, 256, 512) determines which button is the default; the fourth group (0, 4096) determines the modality of the message box, and the fifth group specifies whether or not the message box window is the foreground window, along with the alignment and direction of the text. When adding numbers to create a final value for the Buttons argument, use only one number from each group.
VB.NET 2005
- VB.NET 2005 Free Training
- The .NET Framework Architecture Part 1
- The .NET Framework Architecture Part 2
- Application Class and Message Class
- Implementing Class Library Object
- Visual Studio.NET Namespaces
- .NET Assemblies
- Differences between VB.NET 1.0 and VB.NET 2.0
- Introducing VB.NET Windows Forms
- Visual Studio Windows Forms Designer
- Exploring the Forms Designer generated code
- Setting and Adding Properties to Windows Form
- Implementing Inheritance
- Event Handling In Visual Basic .NET
- Building Graphical Interface elements
- .NET Common Windows Forms Controls Part 1
- .NET Common Windows Forms Controls Part 2
- Common Controls and Handling Control Events
- DomainUpDown and NumericUpDown Controls
- Dialog Boxes in Visual Basic .NET
- Visual Studio Adding Controls to Windows Form
- VB.NET Validation Controls
- Working with Menu Controls
- VB.NET MDI Applications
- .NET Exceptions
- VB.NET Creating and Managing Components Part 1
- VB.NET Creating and Managing Components Part 2
- Simple Data Binding
- .NET Complex Data Binding
- .NET Data Form Wizard
- Data Manipulation with ADO.NET
- SQL Server Stored Procedures
- SQL Server Ad Hoc Queries
- Finding and Sorting Data in DataSets
- ADO.NET Object Model
- Working with DataSets
- Using XML Data
- Working with File System in .NET
- Creating Web Service
- Instantiating - Invoking Web Services, Creating Proxy Classes with WSDL
- Web Reference and Web Services
- Web Services - SOAP, WSDL, Disco and UDDI
- Web Application Testing in VB.NET 2005
- Web Application Tracing and Debugging
- Working with Legacy Code and COM Components
- ActiveX Controls and Legacy Code
- Windows Application Testing
- VB.NET Windows Application Testing
- Tracing VB.NET Windows Application
- Debugging Windows Applications In Visual Studio.NET 2005
- Deploying Windows Applications In Visual Studio.NET 2005
- Customizing Setup Project in Visual Studio.NET 2005
- Shared Assembly
- Microsoft .NET Creating Installation Components
- The Registry Editor in Visual Studio.NET 2005
- The File Types Editor







