VB.Net Tutorial/GUI/MessageBox — различия между версиями
Admin (обсуждение | вклад) м (1 версия) |
(нет различий)
|
Текущая версия на 12:57, 26 мая 2010
Содержание
- 1 Create MessageBox dynamically
- 2 Custom your MessageBox
- 3 Displaying square root of 2 in dialog.
- 4 MessageBox: Abort, Retry, Ignore buttons and Warning icon
- 5 MessageBox Icon and Button
- 6 MessageBox OK and Cancel Button
- 7 MessageBox with Message and Title
- 8 MessageBox with Message only
- 9 MessageBox with OK, Cancel button and Information
- 10 MessageBox with Yes No Cancel button and Question icon
- 11 Return value from MessageBox
- 12 Set default button for MessageBox
Create MessageBox dynamically
Imports System.Windows.Forms
public class MessageBoxCreateDy
public Shared Sub Main
Application.Run(New frmMessageBox)
End Sub
End class
Public Class frmMessageBox
Inherits System.Windows.Forms.Form
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
"This call is required by the Windows Form Designer.
InitializeComponent()
"Add any initialization after the InitializeComponent() call
End Sub
"Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
Friend WithEvents grpPromptandTitle As System.Windows.Forms.GroupBox
Friend WithEvents GroupBox1 As System.Windows.Forms.GroupBox
Friend WithEvents btnShow As System.Windows.Forms.Button
Friend WithEvents Panel1 As System.Windows.Forms.Panel
Friend WithEvents Splitter1 As System.Windows.Forms.Splitter
Friend WithEvents Panel2 As System.Windows.Forms.Panel
Friend WithEvents Label1 As System.Windows.Forms.Label
Friend WithEvents txtText As System.Windows.Forms.TextBox
Friend WithEvents txtCaption As System.Windows.Forms.TextBox
Friend WithEvents Label2 As System.Windows.Forms.Label
Friend WithEvents rdoOKOnly As System.Windows.Forms.RadioButton
Friend WithEvents Label3 As System.Windows.Forms.Label
Friend WithEvents rdoAbRetry As System.Windows.Forms.RadioButton
Friend WithEvents rdoError As System.Windows.Forms.RadioButton
Friend WithEvents rdoExclamation As System.Windows.Forms.RadioButton
Friend WithEvents rdoRetryCancel As System.Windows.Forms.RadioButton
Friend WithEvents rdoInformation As System.Windows.Forms.RadioButton
Friend WithEvents rdoYesNo As System.Windows.Forms.RadioButton
Friend WithEvents rdoYesNoCancel As System.Windows.Forms.RadioButton
Friend WithEvents rdoOKCancel As System.Windows.Forms.RadioButton
Friend WithEvents Label4 As System.Windows.Forms.Label
Friend WithEvents rdoNoIcon As System.Windows.Forms.RadioButton
Friend WithEvents rdoQuestion As System.Windows.Forms.RadioButton
"Required by the Windows Form Designer
Private components As System.ruponentModel.IContainer
"NOTE: The following procedure is required by the Windows Form Designer
"It can be modified using the Windows Form Designer.
"Do not modify it using the code editor.
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.grpPromptandTitle = New System.Windows.Forms.GroupBox()
Me.GroupBox1 = New System.Windows.Forms.GroupBox()
Me.btnShow = New System.Windows.Forms.Button()
Me.Panel1 = New System.Windows.Forms.Panel()
Me.Splitter1 = New System.Windows.Forms.Splitter()
Me.Panel2 = New System.Windows.Forms.Panel()
Me.Label1 = New System.Windows.Forms.Label()
Me.txtText = New System.Windows.Forms.TextBox()
Me.txtCaption = New System.Windows.Forms.TextBox()
Me.Label2 = New System.Windows.Forms.Label()
Me.rdoOKOnly = New System.Windows.Forms.RadioButton()
Me.Label3 = New System.Windows.Forms.Label()
Me.rdoAbRetry = New System.Windows.Forms.RadioButton()
Me.rdoError = New System.Windows.Forms.RadioButton()
Me.rdoExclamation = New System.Windows.Forms.RadioButton()
Me.rdoRetryCancel = New System.Windows.Forms.RadioButton()
Me.rdoInformation = New System.Windows.Forms.RadioButton()
Me.rdoYesNo = New System.Windows.Forms.RadioButton()
Me.rdoYesNoCancel = New System.Windows.Forms.RadioButton()
Me.rdoOKCancel = New System.Windows.Forms.RadioButton()
Me.Label4 = New System.Windows.Forms.Label()
Me.rdoNoIcon = New System.Windows.Forms.RadioButton()
Me.rdoQuestion = New System.Windows.Forms.RadioButton()
Me.grpPromptandTitle.SuspendLayout()
Me.GroupBox1.SuspendLayout()
Me.Panel1.SuspendLayout()
Me.Panel2.SuspendLayout()
Me.SuspendLayout()
"
"grpPromptandTitle
"
Me.grpPromptandTitle.Controls.AddRange(New System.Windows.Forms.Control() {Me.txtCaption, Me.Label2, Me.txtText, Me.Label1})
Me.grpPromptandTitle.Dock = System.Windows.Forms.DockStyle.Top
Me.grpPromptandTitle.Name = "grpPromptandTitle"
Me.grpPromptandTitle.Size = New System.Drawing.Size(456, 112)
Me.grpPromptandTitle.TabIndex = 0
Me.grpPromptandTitle.TabStop = False
Me.grpPromptandTitle.Text = "Enter your text and caption:"
"
"GroupBox1
"
Me.GroupBox1.Controls.AddRange(New System.Windows.Forms.Control() {Me.btnShow})
Me.GroupBox1.Dock = System.Windows.Forms.DockStyle.Bottom
Me.GroupBox1.Location = New System.Drawing.Point(0, 350)
Me.GroupBox1.Name = "GroupBox1"
Me.GroupBox1.Size = New System.Drawing.Size(456, 48)
Me.GroupBox1.TabIndex = 3
Me.GroupBox1.TabStop = False
"
"btnShow
"
Me.btnShow.Location = New System.Drawing.Point(328, 16)
Me.btnShow.Name = "btnShow"
Me.btnShow.Size = New System.Drawing.Size(96, 24)
Me.btnShow.TabIndex = 0
Me.btnShow.Text = "SHOW"
"
"Panel1
"
Me.Panel1.Controls.AddRange(New System.Windows.Forms.Control() {Me.Label3, Me.rdoRetryCancel, Me.rdoYesNo, Me.rdoYesNoCancel, Me.rdoAbRetry, Me.rdoOKCancel, Me.rdoOKOnly})
Me.Panel1.Dock = System.Windows.Forms.DockStyle.Left
Me.Panel1.Location = New System.Drawing.Point(0, 112)
Me.Panel1.Name = "Panel1"
Me.Panel1.Size = New System.Drawing.Size(200, 238)
Me.Panel1.TabIndex = 1
"
"Splitter1
"
Me.Splitter1.Location = New System.Drawing.Point(200, 112)
Me.Splitter1.Name = "Splitter1"
Me.Splitter1.Size = New System.Drawing.Size(3, 238)
Me.Splitter1.TabIndex = 3
Me.Splitter1.TabStop = False
"
"Panel2
"
Me.Panel2.Controls.AddRange(New System.Windows.Forms.Control() {Me.Label4, Me.rdoExclamation, Me.rdoNoIcon, Me.rdoInformation, Me.rdoQuestion, Me.rdoError})
Me.Panel2.Dock = System.Windows.Forms.DockStyle.Fill
Me.Panel2.Location = New System.Drawing.Point(203, 112)
Me.Panel2.Name = "Panel2"
Me.Panel2.Size = New System.Drawing.Size(253, 238)
Me.Panel2.TabIndex = 2
"
"Label1
"
Me.Label1.Location = New System.Drawing.Point(16, 24)
Me.Label1.Name = "Label1"
Me.Label1.Size = New System.Drawing.Size(64, 24)
Me.Label1.TabIndex = 0
Me.Label1.Text = "Text:"
"
"txtText
"
Me.txtText.Location = New System.Drawing.Point(104, 24)
Me.txtText.Name = "txtText"
Me.txtText.Size = New System.Drawing.Size(320, 20)
Me.txtText.TabIndex = 0
Me.txtText.Text = ""
"
"txtCaption
"
Me.txtCaption.Location = New System.Drawing.Point(104, 64)
Me.txtCaption.Name = "txtCaption"
Me.txtCaption.Size = New System.Drawing.Size(320, 20)
Me.txtCaption.TabIndex = 1
Me.txtCaption.Text = ""
"
"Label2
"
Me.Label2.Location = New System.Drawing.Point(16, 64)
Me.Label2.Name = "Label2"
Me.Label2.Size = New System.Drawing.Size(64, 24)
Me.Label2.TabIndex = 0
Me.Label2.Text = "Caption:"
"
"rdoOKOnly
"
Me.rdoOKOnly.Checked = True
Me.rdoOKOnly.Location = New System.Drawing.Point(8, 40)
Me.rdoOKOnly.Name = "rdoOKOnly"
Me.rdoOKOnly.Size = New System.Drawing.Size(160, 24)
Me.rdoOKOnly.TabIndex = 2
Me.rdoOKOnly.TabStop = True
Me.rdoOKOnly.Text = "Ok Only"
"
"Label3
"
Me.Label3.Font = New System.Drawing.Font("Microsoft Sans Serif", 8.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.Label3.Location = New System.Drawing.Point(24, 8)
Me.Label3.Name = "Label3"
Me.Label3.Size = New System.Drawing.Size(104, 24)
Me.Label3.TabIndex = 0
Me.Label3.Text = "Buttons"
"
"rdoAbRetry
"
Me.rdoAbRetry.Location = New System.Drawing.Point(8, 104)
Me.rdoAbRetry.Name = "rdoAbRetry"
Me.rdoAbRetry.Size = New System.Drawing.Size(160, 24)
Me.rdoAbRetry.TabIndex = 4
Me.rdoAbRetry.Text = "Abort, Retry, Ignore"
"
"rdoError
"
Me.rdoError.Checked = True
Me.rdoError.Location = New System.Drawing.Point(24, 40)
Me.rdoError.Name = "rdoError"
Me.rdoError.Size = New System.Drawing.Size(88, 32)
Me.rdoError.TabIndex = 1
Me.rdoError.TabStop = True
Me.rdoError.Text = "Error"
"
"rdoExclamation
"
Me.rdoExclamation.Location = New System.Drawing.Point(24, 112)
Me.rdoExclamation.Name = "rdoExclamation"
Me.rdoExclamation.Size = New System.Drawing.Size(88, 32)
Me.rdoExclamation.TabIndex = 3
Me.rdoExclamation.Text = "Exclamation"
"
"rdoRetryCancel
"
Me.rdoRetryCancel.Location = New System.Drawing.Point(8, 200)
Me.rdoRetryCancel.Name = "rdoRetryCancel"
Me.rdoRetryCancel.Size = New System.Drawing.Size(160, 24)
Me.rdoRetryCancel.TabIndex = 0
Me.rdoRetryCancel.Text = "Retry and Cancel"
"
"rdoInformation
"
Me.rdoInformation.Location = New System.Drawing.Point(136, 40)
Me.rdoInformation.Name = "rdoInformation"
Me.rdoInformation.Size = New System.Drawing.Size(88, 32)
Me.rdoInformation.TabIndex = 4
Me.rdoInformation.Text = "Information"
"
"rdoYesNo
"
Me.rdoYesNo.Location = New System.Drawing.Point(8, 168)
Me.rdoYesNo.Name = "rdoYesNo"
Me.rdoYesNo.Size = New System.Drawing.Size(160, 24)
Me.rdoYesNo.TabIndex = 6
Me.rdoYesNo.Text = "Yes and No"
"
"rdoYesNoCancel
"
Me.rdoYesNoCancel.Location = New System.Drawing.Point(8, 136)
Me.rdoYesNoCancel.Name = "rdoYesNoCancel"
Me.rdoYesNoCancel.Size = New System.Drawing.Size(160, 24)
Me.rdoYesNoCancel.TabIndex = 5
Me.rdoYesNoCancel.Text = "Yes, No, Cancel"
"
"rdoOKCancel
"
Me.rdoOKCancel.Location = New System.Drawing.Point(8, 72)
Me.rdoOKCancel.Name = "rdoOKCancel"
Me.rdoOKCancel.Size = New System.Drawing.Size(160, 24)
Me.rdoOKCancel.TabIndex = 3
Me.rdoOKCancel.Text = "Ok and Cancel"
"
"Label4
"
Me.Label4.Font = New System.Drawing.Font("Microsoft Sans Serif", 8.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.Label4.Location = New System.Drawing.Point(24, 8)
Me.Label4.Name = "Label4"
Me.Label4.Size = New System.Drawing.Size(80, 24)
Me.Label4.TabIndex = 0
Me.Label4.Text = "Icon"
"
"rdoNoIcon
"
Me.rdoNoIcon.Location = New System.Drawing.Point(136, 80)
Me.rdoNoIcon.Name = "rdoNoIcon"
Me.rdoNoIcon.Size = New System.Drawing.Size(88, 32)
Me.rdoNoIcon.TabIndex = 5
Me.rdoNoIcon.Text = "No Icon"
"
"rdoQuestion
"
Me.rdoQuestion.Location = New System.Drawing.Point(24, 80)
Me.rdoQuestion.Name = "rdoQuestion"
Me.rdoQuestion.Size = New System.Drawing.Size(88, 32)
Me.rdoQuestion.TabIndex = 2
Me.rdoQuestion.Text = "Question"
"
"frmMessageBox
"
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(456, 398)
Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.Panel2, Me.Splitter1, Me.Panel1, Me.GroupBox1, Me.grpPromptandTitle})
Me.Name = "frmMessageBox"
Me.Text = "Do the Message Box thing!"
Me.grpPromptandTitle.ResumeLayout(False)
Me.GroupBox1.ResumeLayout(False)
Me.Panel1.ResumeLayout(False)
Me.Panel2.ResumeLayout(False)
Me.ResumeLayout(False)
End Sub
#End Region
Private Sub btnShow_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnShow.Click
Dim buttonchoice As MessageBoxButtons
Dim iconchoice As MessageBoxIcon
Dim answer As DialogResult
If rdoOKOnly.Checked = True Then
buttonchoice = MessageBoxButtons.OK
ElseIf rdoOKCancel.Checked = True Then
buttonchoice = MessageBoxButtons.OKCancel
ElseIf rdoAbRetry.Checked = True Then
buttonchoice = MessageBoxButtons.AbortRetryIgnore
ElseIf rdoYesNoCancel.Checked = True Then
buttonchoice = MessageBoxButtons.YesNoCancel
ElseIf rdoYesNo.Checked = True Then
buttonchoice = MessageBoxButtons.YesNo
ElseIf rdoRetryCancel.Checked = True Then
buttonchoice = MessageBoxButtons.RetryCancel
Else
MessageBox.Show("Unexpected error in button selection!")
End If
If rdoError.Checked = True Then
iconchoice = MessageBoxIcon.Error
ElseIf rdoQuestion.Checked = True Then
iconchoice = MessageBoxIcon.Question
ElseIf rdoExclamation.Checked = True Then
iconchoice = MessageBoxIcon.Exclamation
ElseIf rdoInformation.Checked = True Then
iconchoice = MessageBoxIcon.Information
ElseIf rdoNoIcon.Checked = True Then
iconchoice = MessageBoxIcon.None
Else
MessageBox.Show("Unexpected error in icon selection!")
End If
answer = MessageBox.Show(txtText.Text, txtCaption.Text, _
buttonchoice, iconchoice)
Dim evaluate As String
If answer = DialogResult.OK Then
evaluate = "You clicked OK!"
ElseIf answer = DialogResult.Cancel Then
evaluate = "You clicked Cancel!"
ElseIf answer = DialogResult.Abort Then
evaluate = "You clicked Abort!"
ElseIf answer = DialogResult.Retry Then
evaluate = "You clicked Retry!"
ElseIf answer = DialogResult.Ignore Then
evaluate = "You clicked Ignore!"
ElseIf answer = DialogResult.Yes Then
evaluate = "You clicked Yes!"
ElseIf answer = DialogResult.No Then
evaluate = "You clicked No!"
Else
evaluate = "Nothing was clicked!"
End If
MessageBox.Show(evaluate, "Message Box Evaluation", _
MessageBoxButtons.OK, MessageBoxIcon.Information)
End Sub
End Class
Custom your MessageBox
Imports System.IO
Imports System.Text.Encoding
Imports System.Drawing
Imports System.Drawing.Printing
Imports System.Windows.Forms
public class CustomMessageBox
public Shared Sub Main
Application.Run(New Form1)
End Sub
End class
Public Class Form1
Inherits System.Windows.Forms.Form
Public Sub New()
MyBase.New()
InitializeComponent()
End Sub
Private components As System.ruponentModel.IContainer
Friend WithEvents Label1 As System.Windows.Forms.Label
Friend WithEvents btnShow As System.Windows.Forms.Button
Friend WithEvents txtMsg As System.Windows.Forms.TextBox
Friend WithEvents txtCaption As System.Windows.Forms.TextBox
Friend WithEvents Label2 As System.Windows.Forms.Label
Friend WithEvents grpDefaultButton As System.Windows.Forms.GroupBox
Friend WithEvents DefaultButton3 As System.Windows.Forms.RadioButton
Friend WithEvents DefaultButton2 As System.Windows.Forms.RadioButton
Friend WithEvents DefaultButton1 As System.Windows.Forms.RadioButton
Friend WithEvents GroupBox2 As System.Windows.Forms.GroupBox
Friend WithEvents Button6 As System.Windows.Forms.RadioButton
Friend WithEvents Button5 As System.Windows.Forms.RadioButton
Friend WithEvents Button4 As System.Windows.Forms.RadioButton
Friend WithEvents Button3 As System.Windows.Forms.RadioButton
Friend WithEvents Button2 As System.Windows.Forms.RadioButton
Friend WithEvents Button1 As System.Windows.Forms.RadioButton
Friend WithEvents GroupBox1 As System.Windows.Forms.GroupBox
Friend WithEvents txtResult As System.Windows.Forms.TextBox
Friend WithEvents lblResult As System.Windows.Forms.Label
Friend WithEvents Icon8 As System.Windows.Forms.RadioButton
Friend WithEvents Icon7 As System.Windows.Forms.RadioButton
Friend WithEvents Icon6 As System.Windows.Forms.RadioButton
Friend WithEvents Icon5 As System.Windows.Forms.RadioButton
Friend WithEvents Icon4 As System.Windows.Forms.RadioButton
Friend WithEvents Icon3 As System.Windows.Forms.RadioButton
Friend WithEvents Icon2 As System.Windows.Forms.RadioButton
Friend WithEvents Icon1 As System.Windows.Forms.RadioButton
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.txtMsg = New System.Windows.Forms.TextBox()
Me.Label1 = New System.Windows.Forms.Label()
Me.btnShow = New System.Windows.Forms.Button()
Me.txtCaption = New System.Windows.Forms.TextBox()
Me.Label2 = New System.Windows.Forms.Label()
Me.grpDefaultButton = New System.Windows.Forms.GroupBox()
Me.DefaultButton3 = New System.Windows.Forms.RadioButton()
Me.DefaultButton2 = New System.Windows.Forms.RadioButton()
Me.DefaultButton1 = New System.Windows.Forms.RadioButton()
Me.GroupBox2 = New System.Windows.Forms.GroupBox()
Me.Button6 = New System.Windows.Forms.RadioButton()
Me.Button5 = New System.Windows.Forms.RadioButton()
Me.Button4 = New System.Windows.Forms.RadioButton()
Me.Button3 = New System.Windows.Forms.RadioButton()
Me.Button2 = New System.Windows.Forms.RadioButton()
Me.Button1 = New System.Windows.Forms.RadioButton()
Me.GroupBox1 = New System.Windows.Forms.GroupBox()
Me.Icon8 = New System.Windows.Forms.RadioButton()
Me.Icon7 = New System.Windows.Forms.RadioButton()
Me.Icon6 = New System.Windows.Forms.RadioButton()
Me.Icon5 = New System.Windows.Forms.RadioButton()
Me.Icon4 = New System.Windows.Forms.RadioButton()
Me.Icon3 = New System.Windows.Forms.RadioButton()
Me.Icon2 = New System.Windows.Forms.RadioButton()
Me.Icon1 = New System.Windows.Forms.RadioButton()
Me.txtResult = New System.Windows.Forms.TextBox()
Me.lblResult = New System.Windows.Forms.Label()
Me.grpDefaultButton.SuspendLayout()
Me.GroupBox2.SuspendLayout()
Me.GroupBox1.SuspendLayout()
Me.SuspendLayout()
"
"txtMsg
"
Me.txtMsg.Location = New System.Drawing.Point(68, 8)
Me.txtMsg.Name = "txtMsg"
Me.txtMsg.Size = New System.Drawing.Size(200, 22)
Me.txtMsg.TabIndex = 0
Me.txtMsg.Text = ""
"
"Label1
"
Me.Label1.Location = New System.Drawing.Point(12, 12)
Me.Label1.Name = "Label1"
Me.Label1.Size = New System.Drawing.Size(60, 16)
Me.Label1.TabIndex = 13
Me.Label1.Text = "Message:"
"
"btnShow
"
Me.btnShow.Location = New System.Drawing.Point(280, 8)
Me.btnShow.Name = "btnShow"
Me.btnShow.Size = New System.Drawing.Size(76, 24)
Me.btnShow.TabIndex = 5
Me.btnShow.Text = "Show"
"
"txtCaption
"
Me.txtCaption.Location = New System.Drawing.Point(68, 36)
Me.txtCaption.Name = "txtCaption"
Me.txtCaption.Size = New System.Drawing.Size(200, 22)
Me.txtCaption.TabIndex = 1
Me.txtCaption.Text = ""
"
"Label2
"
Me.Label2.Location = New System.Drawing.Point(12, 40)
Me.Label2.Name = "Label2"
Me.Label2.Size = New System.Drawing.Size(60, 16)
Me.Label2.TabIndex = 16
Me.Label2.Text = "Caption:"
"
"grpDefaultButton
"
Me.grpDefaultButton.Controls.AddRange(New System.Windows.Forms.Control() {Me.DefaultButton3, Me.DefaultButton2, Me.DefaultButton1})
Me.grpDefaultButton.Location = New System.Drawing.Point(208, 72)
Me.grpDefaultButton.Name = "grpDefaultButton"
Me.grpDefaultButton.Size = New System.Drawing.Size(144, 124)
Me.grpDefaultButton.TabIndex = 4
Me.grpDefaultButton.TabStop = False
Me.grpDefaultButton.Text = "Default Button"
"
"DefaultButton3
"
Me.DefaultButton3.Location = New System.Drawing.Point(12, 68)
Me.DefaultButton3.Name = "DefaultButton3"
Me.DefaultButton3.Size = New System.Drawing.Size(100, 20)
Me.DefaultButton3.TabIndex = 2
Me.DefaultButton3.Text = "DefaultButton3"
"
"DefaultButton2
"
Me.DefaultButton2.Location = New System.Drawing.Point(12, 44)
Me.DefaultButton2.Name = "DefaultButton2"
Me.DefaultButton2.Size = New System.Drawing.Size(100, 20)
Me.DefaultButton2.TabIndex = 1
Me.DefaultButton2.Text = "DefaultButton2"
"
"DefaultButton1
"
Me.DefaultButton1.Checked = True
Me.DefaultButton1.Location = New System.Drawing.Point(12, 20)
Me.DefaultButton1.Name = "DefaultButton1"
Me.DefaultButton1.Size = New System.Drawing.Size(100, 20)
Me.DefaultButton1.TabIndex = 0
Me.DefaultButton1.TabStop = True
Me.DefaultButton1.Text = "DefaultButton1"
"
"GroupBox2
"
Me.GroupBox2.Controls.AddRange(New System.Windows.Forms.Control() {Me.Button6, Me.Button5, Me.Button4, Me.Button3, Me.Button2, Me.Button1})
Me.GroupBox2.Location = New System.Drawing.Point(12, 200)
Me.GroupBox2.Name = "GroupBox2"
Me.GroupBox2.Size = New System.Drawing.Size(188, 160)
Me.GroupBox2.TabIndex = 3
Me.GroupBox2.TabStop = False
Me.GroupBox2.Text = "Buttons"
"
"Button6
"
Me.Button6.Location = New System.Drawing.Point(12, 133)
Me.Button6.Name = "Button6"
Me.Button6.Size = New System.Drawing.Size(100, 19)
Me.Button6.TabIndex = 5
Me.Button6.Text = "YesNoCancel"
"
"Button5
"
Me.Button5.Checked = True
Me.Button5.Location = New System.Drawing.Point(12, 110)
Me.Button5.Name = "Button5"
Me.Button5.Size = New System.Drawing.Size(100, 20)
Me.Button5.TabIndex = 4
Me.Button5.TabStop = True
Me.Button5.Text = "YesNo"
"
"Button4
"
Me.Button4.Location = New System.Drawing.Point(12, 86)
Me.Button4.Name = "Button4"
Me.Button4.Size = New System.Drawing.Size(100, 21)
Me.Button4.TabIndex = 3
Me.Button4.Text = "RetryCancel"
"
"Button3
"
Me.Button3.Location = New System.Drawing.Point(12, 65)
Me.Button3.Name = "Button3"
Me.Button3.Size = New System.Drawing.Size(100, 18)
Me.Button3.TabIndex = 2
Me.Button3.Text = "OKCancel"
"
"Button2
"
Me.Button2.Location = New System.Drawing.Point(12, 43)
Me.Button2.Name = "Button2"
Me.Button2.Size = New System.Drawing.Size(100, 19)
Me.Button2.TabIndex = 1
Me.Button2.Text = "OK"
"
"Button1
"
Me.Button1.Location = New System.Drawing.Point(12, 20)
Me.Button1.Name = "Button1"
Me.Button1.Size = New System.Drawing.Size(112, 20)
Me.Button1.TabIndex = 0
Me.Button1.Text = "AbortRetryIgnore"
"
"GroupBox1
"
Me.GroupBox1.Controls.AddRange(New System.Windows.Forms.Control() {Me.Icon8, Me.Icon7, Me.Icon6, Me.Icon5, Me.Icon4, Me.Icon3, Me.Icon2, Me.Icon1})
Me.GroupBox1.Location = New System.Drawing.Point(12, 72)
Me.GroupBox1.Name = "GroupBox1"
Me.GroupBox1.Size = New System.Drawing.Size(188, 124)
Me.GroupBox1.TabIndex = 2
Me.GroupBox1.TabStop = False
Me.GroupBox1.Text = "Icon"
"
"Icon8
"
Me.Icon8.Location = New System.Drawing.Point(100, 92)
Me.Icon8.Name = "Icon8"
Me.Icon8.Size = New System.Drawing.Size(64, 20)
Me.Icon8.TabIndex = 7
Me.Icon8.Text = "Warning"
"
"Icon7
"
Me.Icon7.Location = New System.Drawing.Point(12, 92)
Me.Icon7.Name = "Icon7"
Me.Icon7.Size = New System.Drawing.Size(84, 20)
Me.Icon7.TabIndex = 6
Me.Icon7.Text = "Stop"
"
"Icon6
"
Me.Icon6.Location = New System.Drawing.Point(100, 68)
Me.Icon6.Name = "Icon6"
Me.Icon6.Size = New System.Drawing.Size(64, 20)
Me.Icon6.TabIndex = 5
Me.Icon6.Text = "Question"
"
"Icon5
"
Me.Icon5.Checked = True
Me.Icon5.Location = New System.Drawing.Point(12, 68)
Me.Icon5.Name = "Icon5"
Me.Icon5.Size = New System.Drawing.Size(84, 20)
Me.Icon5.TabIndex = 4
Me.Icon5.TabStop = True
Me.Icon5.Text = "Information"
"
"Icon4
"
Me.Icon4.Location = New System.Drawing.Point(100, 44)
Me.Icon4.Name = "Icon4"
Me.Icon4.Size = New System.Drawing.Size(64, 20)
Me.Icon4.TabIndex = 3
Me.Icon4.Text = "Hand"
"
"Icon3
"
Me.Icon3.Location = New System.Drawing.Point(12, 44)
Me.Icon3.Name = "Icon3"
Me.Icon3.Size = New System.Drawing.Size(84, 20)
Me.Icon3.TabIndex = 2
Me.Icon3.Text = "Exclamation"
"
"Icon2
"
Me.Icon2.Location = New System.Drawing.Point(100, 20)
Me.Icon2.Name = "Icon2"
Me.Icon2.Size = New System.Drawing.Size(64, 20)
Me.Icon2.TabIndex = 1
Me.Icon2.Text = "Error"
"
"Icon1
"
Me.Icon1.Location = New System.Drawing.Point(12, 20)
Me.Icon1.Name = "Icon1"
Me.Icon1.Size = New System.Drawing.Size(84, 20)
Me.Icon1.TabIndex = 0
Me.Icon1.Text = "Asterisk"
"
"txtResult
"
Me.txtResult.Enabled = False
Me.txtResult.Location = New System.Drawing.Point(212, 232)
Me.txtResult.Name = "txtResult"
Me.txtResult.Size = New System.Drawing.Size(136, 22)
Me.txtResult.TabIndex = 18
Me.txtResult.Text = ""
"
"lblResult
"
Me.lblResult.Location = New System.Drawing.Point(212, 208)
Me.lblResult.Name = "lblResult"
Me.lblResult.Size = New System.Drawing.Size(56, 20)
Me.lblResult.TabIndex = 17
Me.lblResult.Text = "Result"
"
"Form1
"
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 15)
Me.ClientSize = New System.Drawing.Size(368, 369)
Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.grpDefaultButton, Me.GroupBox2, Me.GroupBox1, Me.txtResult, Me.lblResult, Me.txtCaption, Me.Label2, Me.btnShow, Me.txtMsg, Me.Label1})
Me.Name = "Form1"
Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
Me.Text = "MessageBox Application"
Me.grpDefaultButton.ResumeLayout(False)
Me.GroupBox2.ResumeLayout(False)
Me.GroupBox1.ResumeLayout(False)
Me.ResumeLayout(False)
End Sub
Private iIcon As Integer
Private iButton As Integer
Private iDefaultButton As Integer
Private Sub btnShow_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnShow.Click
Dim iResult As Integer
iResult = MessageBox.Show(Me,txtMsg.Text, txtCaption.Text, iButton, iIcon, iDefaultButton)
Select Case iResult
Case DialogResult.Abort
txtResult.Text = "DialogResult.Abort"
Case DialogResult.Retry
txtResult.Text = "DialogResult.Retry"
Case DialogResult.Ignore
txtResult.Text = "DialogResult.Ignore"
Case DialogResult.OK
txtResult.Text = "DialogResult.OK"
Case DialogResult.Cancel
txtResult.Text = "DialogResult.Cancel"
Case DialogResult.Yes
txtResult.Text = "DialogResult.Yes"
Case DialogResult.No
txtResult.Text = "DialogResult.No"
End Select
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
AddHandler Icon1.Click, AddressOf Icon_Click
AddHandler Icon2.Click, AddressOf Icon_Click
AddHandler Icon3.Click, AddressOf Icon_Click
AddHandler Icon4.Click, AddressOf Icon_Click
AddHandler Icon5.Click, AddressOf Icon_Click
AddHandler Icon6.Click, AddressOf Icon_Click
AddHandler Icon7.Click, AddressOf Icon_Click
AddHandler Icon8.Click, AddressOf Icon_Click
AddHandler Button1.Click, AddressOf Button_Click
AddHandler Button2.Click, AddressOf Button_Click
AddHandler Button3.Click, AddressOf Button_Click
AddHandler Button4.Click, AddressOf Button_Click
AddHandler Button5.Click, AddressOf Button_Click
AddHandler Button6.Click, AddressOf Button_Click
AddHandler DefaultButton1.Click, AddressOf DefaultButton_Click
AddHandler DefaultButton2.Click, AddressOf DefaultButton_Click
AddHandler DefaultButton3.Click, AddressOf DefaultButton_Click
iIcon = MessageBoxIcon.Information
iButton = MessageBoxButtons.YesNo
iDefaultButton = MessageBoxDefaultButton.Button1
End Sub
Public Sub Icon_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Select Case sender.Name
Case "Icon1"
iIcon = MessageBoxIcon.Asterisk
Case "Icon2"
iIcon = MessageBoxIcon.Error
Case "Icon3"
iIcon = MessageBoxIcon.Exclamation
Case "Icon4"
iIcon = MessageBoxIcon.Hand
Case "Icon5"
iIcon = MessageBoxIcon.Information
Case "Icon6"
iIcon = MessageBoxIcon.Question
Case "Icon7"
iIcon = MessageBoxIcon.Stop
Case "Icon8"
iIcon = MessageBoxIcon.Warning
End Select
End Sub
Public Sub Button_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Select Case sender.Name
Case "Button1"
iButton = MessageBoxButtons.AbortRetryIgnore
Case "Button2"
iButton = MessageBoxButtons.OK
Case "Button3"
iButton = MessageBoxButtons.OKCancel
Case "Button4"
iButton = MessageBoxButtons.RetryCancel
Case "Button5"
iButton = MessageBoxButtons.YesNo
Case "Button6"
iButton = MessageBoxButtons.YesNoCancel
End Select
End Sub
Public Sub DefaultButton_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Select Case sender.Name
Case "DefaultButton1"
iDefaultButton = MessageBoxDefaultButton.Button1
Case "DefaultButton2"
iDefaultButton = MessageBoxDefaultButton.Button2
Case "DefaultButton3"
iDefaultButton = MessageBoxDefaultButton.Button3
End Select
End Sub
End Class
Displaying square root of 2 in dialog.
Imports System.Windows.Forms " Namespace containing MessageBox
Module modSquareRoot
Sub Main()
Dim root As Double = Math.Sqrt(2)
MessageBox.Show("The square root of 2 is " & root, _
"The Square Root of 2")
End Sub
End Module
MessageBox: Abort, Retry, Ignore buttons and Warning icon
Imports System.Windows.Forms
public class MessageBoxWithMessageAndTile
public Shared Sub Main
MessageBox.Show("Message", "Title", MessageBoxButtons.AbortRetryIgnore, MessageBoxIcon.Warn
ing)
End Sub
End class
MessageBox Icon and Button
Imports System.Windows.Forms
public class RadioButtonAction
public Shared Sub Main
Application.Run(New FrmRadioButton)
End Sub
End class
Public Class FrmRadioButton
Inherits System.Windows.Forms.Form
Private iconType As MessageBoxIcon
Private buttonType As MessageBoxButtons
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
"This call is required by the Windows Form Designer.
InitializeComponent()
"Add any initialization after the InitializeComponent() call
End Sub
"Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
Friend WithEvents iconGroupBox As System.Windows.Forms.GroupBox
Friend WithEvents buttonTypeGroupBox As System.Windows.Forms.GroupBox
Friend WithEvents radRetryCancel As System.Windows.Forms.RadioButton
Friend WithEvents radYesNo As System.Windows.Forms.RadioButton
Friend WithEvents radAbortRetryIgnore As System.Windows.Forms.RadioButton
Friend WithEvents radOk As System.Windows.Forms.RadioButton
Friend WithEvents radWarning As System.Windows.Forms.RadioButton
Friend WithEvents radStop As System.Windows.Forms.RadioButton
Friend WithEvents radQuestion As System.Windows.Forms.RadioButton
Friend WithEvents radInformation As System.Windows.Forms.RadioButton
Friend WithEvents radHand As System.Windows.Forms.RadioButton
Friend WithEvents radExclamation As System.Windows.Forms.RadioButton
Friend WithEvents radError As System.Windows.Forms.RadioButton
Friend WithEvents radAsterisk As System.Windows.Forms.RadioButton
Friend WithEvents cmdDisplay As System.Windows.Forms.Button
Friend WithEvents lblDisplay As System.Windows.Forms.Label
Friend WithEvents radOkCancel As System.Windows.Forms.RadioButton
Friend WithEvents radYesNoCancel As System.Windows.Forms.RadioButton
"Required by the Windows Form Designer
Private components As System.ruponentModel.Container
"NOTE: The following procedure is required by the Windows Form Designer
"It can be modified using the Windows Form Designer.
"Do not modify it using the code editor.
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.radAbortRetryIgnore = New System.Windows.Forms.RadioButton()
Me.radStop = New System.Windows.Forms.RadioButton()
Me.radYesNo = New System.Windows.Forms.RadioButton()
Me.iconGroupBox = New System.Windows.Forms.GroupBox()
Me.radWarning = New System.Windows.Forms.RadioButton()
Me.radQuestion = New System.Windows.Forms.RadioButton()
Me.radInformation = New System.Windows.Forms.RadioButton()
Me.radHand = New System.Windows.Forms.RadioButton()
Me.radExclamation = New System.Windows.Forms.RadioButton()
Me.radError = New System.Windows.Forms.RadioButton()
Me.radAsterisk = New System.Windows.Forms.RadioButton()
Me.radYesNoCancel = New System.Windows.Forms.RadioButton()
Me.radOk = New System.Windows.Forms.RadioButton()
Me.cmdDisplay = New System.Windows.Forms.Button()
Me.lblDisplay = New System.Windows.Forms.Label()
Me.buttonTypeGroupBox = New System.Windows.Forms.GroupBox()
Me.radRetryCancel = New System.Windows.Forms.RadioButton()
Me.radOkCancel = New System.Windows.Forms.RadioButton()
Me.iconGroupBox.SuspendLayout()
Me.buttonTypeGroupBox.SuspendLayout()
Me.SuspendLayout()
"
"radAbortRetryIgnore
"
Me.radAbortRetryIgnore.Location = New System.Drawing.Point(16, 88)
Me.radAbortRetryIgnore.Name = "radAbortRetryIgnore"
Me.radAbortRetryIgnore.Size = New System.Drawing.Size(120, 24)
Me.radAbortRetryIgnore.TabIndex = 2
Me.radAbortRetryIgnore.Text = "AbortRetryIgnore"
"
"radStop
"
Me.radStop.Location = New System.Drawing.Point(16, 240)
Me.radStop.Name = "radStop"
Me.radStop.Size = New System.Drawing.Size(128, 24)
Me.radStop.TabIndex = 6
Me.radStop.Text = "Stop"
"
"radYesNo
"
Me.radYesNo.Location = New System.Drawing.Point(16, 160)
Me.radYesNo.Name = "radYesNo"
Me.radYesNo.Size = New System.Drawing.Size(120, 16)
Me.radYesNo.TabIndex = 4
Me.radYesNo.Text = "YesNo"
"
"iconGroupBox
"
Me.iconGroupBox.Controls.AddRange(New System.Windows.Forms.Control() {Me.radWarning, Me.radStop, Me.radQuestion, Me.radInformation, Me.radHand, Me.radExclamation, Me.radError, Me.radAsterisk})
Me.iconGroupBox.Location = New System.Drawing.Point(200, 16)
Me.iconGroupBox.Name = "iconGroupBox"
Me.iconGroupBox.Size = New System.Drawing.Size(160, 304)
Me.iconGroupBox.TabIndex = 3
Me.iconGroupBox.TabStop = False
Me.iconGroupBox.Text = "Icon"
"
"radWarning
"
Me.radWarning.Location = New System.Drawing.Point(16, 272)
Me.radWarning.Name = "radWarning"
Me.radWarning.Size = New System.Drawing.Size(128, 24)
Me.radWarning.TabIndex = 7
Me.radWarning.Text = "Warning"
"
"radQuestion
"
Me.radQuestion.Location = New System.Drawing.Point(16, 208)
Me.radQuestion.Name = "radQuestion"
Me.radQuestion.Size = New System.Drawing.Size(128, 24)
Me.radQuestion.TabIndex = 5
Me.radQuestion.Text = "Question"
"
"radInformation
"
Me.radInformation.Location = New System.Drawing.Point(16, 168)
Me.radInformation.Name = "radInformation"
Me.radInformation.Size = New System.Drawing.Size(128, 24)
Me.radInformation.TabIndex = 4
Me.radInformation.Text = "Information"
"
"radHand
"
Me.radHand.Location = New System.Drawing.Point(16, 128)
Me.radHand.Name = "radHand"
Me.radHand.Size = New System.Drawing.Size(128, 24)
Me.radHand.TabIndex = 3
Me.radHand.Text = "Hand"
"
"radExclamation
"
Me.radExclamation.Location = New System.Drawing.Point(16, 88)
Me.radExclamation.Name = "radExclamation"
Me.radExclamation.Size = New System.Drawing.Size(136, 24)
Me.radExclamation.TabIndex = 2
Me.radExclamation.Text = "Exclamation"
"
"radError
"
Me.radError.Location = New System.Drawing.Point(16, 48)
Me.radError.Name = "radError"
Me.radError.Size = New System.Drawing.Size(136, 24)
Me.radError.TabIndex = 1
Me.radError.Text = "Error"
"
"radAsterisk
"
Me.radAsterisk.Location = New System.Drawing.Point(16, 16)
Me.radAsterisk.Name = "radAsterisk"
Me.radAsterisk.Size = New System.Drawing.Size(136, 24)
Me.radAsterisk.TabIndex = 0
Me.radAsterisk.Text = "Asterisk"
"
"radYesNoCancel
"
Me.radYesNoCancel.Location = New System.Drawing.Point(16, 120)
Me.radYesNoCancel.Name = "radYesNoCancel"
Me.radYesNoCancel.Size = New System.Drawing.Size(120, 24)
Me.radYesNoCancel.TabIndex = 3
Me.radYesNoCancel.Text = "YesNoCancel"
"
"radOk
"
Me.radOk.Location = New System.Drawing.Point(16, 24)
Me.radOk.Name = "radOk"
Me.radOk.Size = New System.Drawing.Size(112, 16)
Me.radOk.TabIndex = 0
Me.radOk.Text = "OK"
"
"cmdDisplay
"
Me.cmdDisplay.Location = New System.Drawing.Point(32, 240)
Me.cmdDisplay.Name = "cmdDisplay"
Me.cmdDisplay.Size = New System.Drawing.Size(112, 40)
Me.cmdDisplay.TabIndex = 1
Me.cmdDisplay.Text = "Display"
"
"lblDisplay
"
Me.lblDisplay.Location = New System.Drawing.Point(24, 296)
Me.lblDisplay.Name = "lblDisplay"
Me.lblDisplay.Size = New System.Drawing.Size(144, 24)
Me.lblDisplay.TabIndex = 5
"
"buttonTypeGroupBox
"
Me.buttonTypeGroupBox.Controls.AddRange(New System.Windows.Forms.Control() {Me.radRetryCancel, Me.radYesNo, Me.radYesNoCancel, Me.radAbortRetryIgnore, Me.radOkCancel, Me.radOk})
Me.buttonTypeGroupBox.Location = New System.Drawing.Point(16, 16)
Me.buttonTypeGroupBox.Name = "buttonTypeGroupBox"
Me.buttonTypeGroupBox.Size = New System.Drawing.Size(144, 216)
Me.buttonTypeGroupBox.TabIndex = 2
Me.buttonTypeGroupBox.TabStop = False
Me.buttonTypeGroupBox.Text = "Button Type"
"
"radRetryCancel
"
Me.radRetryCancel.Location = New System.Drawing.Point(16, 192)
Me.radRetryCancel.Name = "radRetryCancel"
Me.radRetryCancel.Size = New System.Drawing.Size(104, 16)
Me.radRetryCancel.TabIndex = 5
Me.radRetryCancel.Text = "RetryCancel"
"
"radOkCancel
"
Me.radOkCancel.Location = New System.Drawing.Point(16, 56)
Me.radOkCancel.Name = "radOkCancel"
Me.radOkCancel.Size = New System.Drawing.Size(120, 24)
Me.radOkCancel.TabIndex = 1
Me.radOkCancel.Text = "OKCancel"
"
"FrmRadioButton
"
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(384, 333)
Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.lblDisplay, Me.iconGroupBox, Me.buttonTypeGroupBox, Me.cmdDisplay})
Me.Name = "FrmRadioButton"
Me.Text = "RadioButtonTest"
Me.iconGroupBox.ResumeLayout(False)
Me.buttonTypeGroupBox.ResumeLayout(False)
Me.ResumeLayout(False)
End Sub
#End Region
Private Sub cmdDisplay_Click(ByVal sender _
As System.Object, ByVal e As System.EventArgs) _
Handles cmdDisplay.Click
Dim dialog As DialogResult = MessageBox.Show( _
"Your message", "Title", _
buttonType, iconType)
Select Case dialog
Case DialogResult.OK
lblDisplay.Text = "OK was pressed"
Case DialogResult.Cancel
lblDisplay.Text = "Cancel was pressed"
Case DialogResult.Abort
lblDisplay.Text = "Abort was pressed"
Case DialogResult.Retry
lblDisplay.Text = "Retry was pressed"
Case DialogResult.Ignore
lblDisplay.Text = "Ignore was pressed"
Case DialogResult.Yes
lblDisplay.Text = "Yes was pressed"
Case DialogResult.No
lblDisplay.Text = "No was pressed"
End Select
End Sub " cmdDisplay_Click
Private Sub radOk_CheckedChanged(ByVal sender _
As System.Object, ByVal e As System.EventArgs) _
Handles radOk.CheckedChanged
buttonType = MessageBoxButtons.OK
End Sub
Private Sub radOkCancel_CheckedChanged(ByVal sender _
As System.Object, ByVal e As System.EventArgs) _
Handles radOkCancel.CheckedChanged
buttonType = MessageBoxButtons.OKCancel
End Sub
Private Sub radAbortRetryIgnore_CheckedChanged(ByVal sender _
As System.Object, ByVal e As System.EventArgs) _
Handles radAbortRetryIgnore.CheckedChanged
buttonType = MessageBoxButtons.AbortRetryIgnore
End Sub
Private Sub radYesNoCancel_CheckedChanged(ByVal sender _
As System.Object, ByVal e As System.EventArgs) _
Handles radYesNoCancel.CheckedChanged
buttonType = MessageBoxButtons.YesNoCancel
End Sub
Private Sub radYesNo_CheckedChanged(ByVal sender _
As System.Object, ByVal e As System.EventArgs) _
Handles radYesNo.CheckedChanged
buttonType = MessageBoxButtons.YesNo
End Sub
Private Sub radRetryCancel_CheckedChanged(ByVal sender _
As System.Object, ByVal e As System.EventArgs) _
Handles radRetryCancel.CheckedChanged
buttonType = MessageBoxButtons.RetryCancel
End Sub
Private Sub radAsterisk_CheckedChanged(ByVal sender _
As System.Object, ByVal e As System.EventArgs) _
Handles radAsterisk.CheckedChanged
iconType = MessageBoxIcon.Asterisk
End Sub
Private Sub radError_CheckedChanged(ByVal sender _
As System.Object, ByVal e As System.EventArgs) _
Handles radError.CheckedChanged
iconType = MessageBoxIcon.Error
End Sub
Private Sub radExclamation_CheckedChanged(ByVal sender _
As System.Object, ByVal e As System.EventArgs) _
Handles radExclamation.CheckedChanged
iconType = MessageBoxIcon.Exclamation
End Sub
Private Sub radHand_CheckedChanged(ByVal sender _
As System.Object, ByVal e As System.EventArgs) _
Handles radHand.CheckedChanged
iconType = MessageBoxIcon.Hand
End Sub
Private Sub radInformation_CheckedChanged(ByVal sender _
As System.Object, ByVal e As System.EventArgs) _
Handles radInformation.CheckedChanged
iconType = MessageBoxIcon.Information
End Sub
Private Sub radQuestion_CheckedChanged(ByVal sender _
As System.Object, ByVal e As System.EventArgs) _
Handles radQuestion.CheckedChanged
iconType = MessageBoxIcon.Question
End Sub
Private Sub radStop_CheckedChanged(ByVal sender _
As System.Object, ByVal e As System.EventArgs) _
Handles radStop.CheckedChanged
iconType = MessageBoxIcon.Stop
End Sub
Private Sub radWarning_CheckedChanged(ByVal sender _
As System.Object, ByVal e As System.EventArgs) _
Handles radWarning.CheckedChanged
iconType = MessageBoxIcon.Warning
End Sub
End Class
MessageBox OK and Cancel Button
Imports System.Windows.Forms
public class MessageBoxWithMessageAndTile
public Shared Sub Main
MessageBox.Show("Message", "Title", MessageBoxButtons.OKCancel)
End Sub
End class
MessageBox with Message and Title
Imports System.Windows.Forms
public class MessageBoxWithMessageAndTile
public Shared Sub Main
MessageBox.Show("Message", "Title")
End Sub
End class
MessageBox with Message only
Imports System.Windows.Forms
public class MessageBoxWithMessageOnly
public Shared Sub Main
MessageBox.Show("Message")
End Sub
End class
MessageBox with OK, Cancel button and Information
Imports System.Windows.Forms
public class MessageBoxOKCancelInformation
public Shared Sub Main
Dim answer As DialogResult
answer = MessageBox.Show("A","B", MessageBoxButtons.OKCancel,MessageBoxIcon.Information)
End Sub
End class
MessageBox with Yes No Cancel button and Question icon
Imports System.Windows.Forms
public class MessageBoxYesNoCancelQuestion
public Shared Sub Main
Dim answer As DialogResult
answer = MessageBox.Show("A", "B", _
MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question)
End Sub
End class
Return value from MessageBox
Imports System.Drawing
Imports System.Drawing.Drawing2D
Imports System.Windows.Forms
public class MessageBoxReturnValue
public Shared Sub Main
Dim intReturnValue As Integer
intReturnValue = MessageBox.Show("This is also a message box!", "Message Box", _
MessageBoxButtons.OKCancel, MessageBoxIcon.Information, _
MessageBoxDefaultButton.Button1, MessageBoxOptions.DefaultDesktopOnly)
If (intReturnValue = DialogResult.OK) Then
Console.WriteLine("You clicked the OK button.")
End If
End Sub
End class
Set default button for MessageBox
Imports System.Windows.Forms
public class MessageBoxDefaultButtonDemo
public Shared Sub Main
Dim answer As DialogResult
answer = MessageBox.Show("A", "B",MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question, _
MessageBoxDefaultButton.Button2)
End Sub
End class