Custom your MessageBox : MessageBox « GUI « VB.Net Tutorial

VB.Net Tutorial
1. Language Basics
2. Data Type
3. Operator
4. Statements
5. Date Time
6. Class Module
7. Development
8. Collections
9. Generics
10. Attributes
11. Event
12. Stream File
13. GUI
14. GUI Applications
15. 2D Graphics
16. I18N Internationlization
17. Reflection
18. Regular Expressions
19. Security
20. Socket Network
21. Thread
22. Windows
23. XML
24. Database ADO.net
25. Design Patterns
Java
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
VB.Net Tutorial » GUI » MessageBox 
13. 59. 11. Custom your MessageBox
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.ComponentModel.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(688)
    Me.txtMsg.Name = "txtMsg"
    Me.txtMsg.Size = New System.Drawing.Size(20022)
    Me.txtMsg.TabIndex = 0
    Me.txtMsg.Text = ""
    '
    'Label1
    '
    Me.Label1.Location = New System.Drawing.Point(1212)
    Me.Label1.Name = "Label1"
    Me.Label1.Size = New System.Drawing.Size(6016)
    Me.Label1.TabIndex = 13
    Me.Label1.Text = "Message:"
    '
    'btnShow
    '
    Me.btnShow.Location = New System.Drawing.Point(2808)
    Me.btnShow.Name = "btnShow"
    Me.btnShow.Size = New System.Drawing.Size(7624)
    Me.btnShow.TabIndex = 5
    Me.btnShow.Text = "Show"
    '
    'txtCaption
    '
    Me.txtCaption.Location = New System.Drawing.Point(6836)
    Me.txtCaption.Name = "txtCaption"
    Me.txtCaption.Size = New System.Drawing.Size(20022)
    Me.txtCaption.TabIndex = 1
    Me.txtCaption.Text = ""
    '
    'Label2
    '
    Me.Label2.Location = New System.Drawing.Point(1240)
    Me.Label2.Name = "Label2"
    Me.Label2.Size = New System.Drawing.Size(6016)
    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(20872)
    Me.grpDefaultButton.Name = "grpDefaultButton"
    Me.grpDefaultButton.Size = New System.Drawing.Size(144124)
    Me.grpDefaultButton.TabIndex = 4
    Me.grpDefaultButton.TabStop = False
    Me.grpDefaultButton.Text = "Default Button"
    '
    'DefaultButton3
    '
    Me.DefaultButton3.Location = New System.Drawing.Point(1268)
    Me.DefaultButton3.Name = "DefaultButton3"
    Me.DefaultButton3.Size = New System.Drawing.Size(10020)
    Me.DefaultButton3.TabIndex = 2
    Me.DefaultButton3.Text = "DefaultButton3"
    '
    'DefaultButton2
    '
    Me.DefaultButton2.Location = New System.Drawing.Point(1244)
    Me.DefaultButton2.Name = "DefaultButton2"
    Me.DefaultButton2.Size = New System.Drawing.Size(10020)
    Me.DefaultButton2.TabIndex = 1
    Me.DefaultButton2.Text = "DefaultButton2"
    '
    'DefaultButton1
    '
    Me.DefaultButton1.Checked = True
    Me.DefaultButton1.Location = New System.Drawing.Point(1220)
    Me.DefaultButton1.Name = "DefaultButton1"
    Me.DefaultButton1.Size = New System.Drawing.Size(10020)
    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(12200)
    Me.GroupBox2.Name = "GroupBox2"
    Me.GroupBox2.Size = New System.Drawing.Size(188160)
    Me.GroupBox2.TabIndex = 3
    Me.GroupBox2.TabStop = False
    Me.GroupBox2.Text = "Buttons"
    '
    'Button6
    '
    Me.Button6.Location = New System.Drawing.Point(12133)
    Me.Button6.Name = "Button6"
    Me.Button6.Size = New System.Drawing.Size(10019)
    Me.Button6.TabIndex = 5
    Me.Button6.Text = "YesNoCancel"
    '
    'Button5
    '
    Me.Button5.Checked = True
    Me.Button5.Location = New System.Drawing.Point(12110)
    Me.Button5.Name = "Button5"
    Me.Button5.Size = New System.Drawing.Size(10020)
    Me.Button5.TabIndex = 4
    Me.Button5.TabStop = True
    Me.Button5.Text = "YesNo"
    '
    'Button4
    '
    Me.Button4.Location = New System.Drawing.Point(1286)
    Me.Button4.Name = "Button4"
    Me.Button4.Size = New System.Drawing.Size(10021)
    Me.Button4.TabIndex = 3
    Me.Button4.Text = "RetryCancel"
    '
    'Button3
    '
    Me.Button3.Location = New System.Drawing.Point(1265)
    Me.Button3.Name = "Button3"
    Me.Button3.Size = New System.Drawing.Size(10018)
    Me.Button3.TabIndex = 2
    Me.Button3.Text = "OKCancel"
    '
    'Button2
    '
    Me.Button2.Location = New System.Drawing.Point(1243)
    Me.Button2.Name = "Button2"
    Me.Button2.Size = New System.Drawing.Size(10019)
    Me.Button2.TabIndex = 1
    Me.Button2.Text = "OK"
    '
    'Button1
    '
    Me.Button1.Location = New System.Drawing.Point(1220)
    Me.Button1.Name = "Button1"
    Me.Button1.Size = New System.Drawing.Size(11220)
    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(1272)
    Me.GroupBox1.Name = "GroupBox1"
    Me.GroupBox1.Size = New System.Drawing.Size(188124)
    Me.GroupBox1.TabIndex = 2
    Me.GroupBox1.TabStop = False
    Me.GroupBox1.Text = "Icon"
    '
    'Icon8
    '
    Me.Icon8.Location = New System.Drawing.Point(10092)
    Me.Icon8.Name = "Icon8"
    Me.Icon8.Size = New System.Drawing.Size(6420)
    Me.Icon8.TabIndex = 7
    Me.Icon8.Text = "Warning"
    '
    'Icon7
    '
    Me.Icon7.Location = New System.Drawing.Point(1292)
    Me.Icon7.Name = "Icon7"
    Me.Icon7.Size = New System.Drawing.Size(8420)
    Me.Icon7.TabIndex = 6
    Me.Icon7.Text = "Stop"
    '
    'Icon6
    '
    Me.Icon6.Location = New System.Drawing.Point(10068)
    Me.Icon6.Name = "Icon6"
    Me.Icon6.Size = New System.Drawing.Size(6420)
    Me.Icon6.TabIndex = 5
    Me.Icon6.Text = "Question"
    '
    'Icon5
    '
    Me.Icon5.Checked = True
    Me.Icon5.Location = New System.Drawing.Point(1268)
    Me.Icon5.Name = "Icon5"
    Me.Icon5.Size = New System.Drawing.Size(8420)
    Me.Icon5.TabIndex = 4
    Me.Icon5.TabStop = True
    Me.Icon5.Text = "Information"
    '
    'Icon4
    '
    Me.Icon4.Location = New System.Drawing.Point(10044)
    Me.Icon4.Name = "Icon4"
    Me.Icon4.Size = New System.Drawing.Size(6420)
    Me.Icon4.TabIndex = 3
    Me.Icon4.Text = "Hand"
    '
    'Icon3
    '
    Me.Icon3.Location = New System.Drawing.Point(1244)
    Me.Icon3.Name = "Icon3"
    Me.Icon3.Size = New System.Drawing.Size(8420)
    Me.Icon3.TabIndex = 2
    Me.Icon3.Text = "Exclamation"
    '
    'Icon2
    '
    Me.Icon2.Location = New System.Drawing.Point(10020)
    Me.Icon2.Name = "Icon2"
    Me.Icon2.Size = New System.Drawing.Size(6420)
    Me.Icon2.TabIndex = 1
    Me.Icon2.Text = "Error"
    '
    'Icon1
    '
    Me.Icon1.Location = New System.Drawing.Point(1220)
    Me.Icon1.Name = "Icon1"
    Me.Icon1.Size = New System.Drawing.Size(8420)
    Me.Icon1.TabIndex = 0
    Me.Icon1.Text = "Asterisk"
    '
    'txtResult
    '
    Me.txtResult.Enabled = False
    Me.txtResult.Location = New System.Drawing.Point(212232)
    Me.txtResult.Name = "txtResult"
    Me.txtResult.Size = New System.Drawing.Size(13622)
    Me.txtResult.TabIndex = 18
    Me.txtResult.Text = ""
    '
    'lblResult
    '
    Me.lblResult.Location = New System.Drawing.Point(212208)
    Me.lblResult.Name = "lblResult"
    Me.lblResult.Size = New System.Drawing.Size(5620)
    Me.lblResult.TabIndex = 17
    Me.lblResult.Text = "Result"
    '
    'Form1
    '
    Me.AutoScaleBaseSize = New System.Drawing.Size(515)
    Me.ClientSize = New System.Drawing.Size(368369)
    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.EventArgsHandles 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.EventArgsHandles 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
13. 59. MessageBox
13. 59. 1. MessageBox with Message onlyMessageBox with Message only
13. 59. 2. MessageBox with Message and TitleMessageBox with Message and Title
13. 59. 3. MessageBox with OK, Cancel button and InformationMessageBox with OK, Cancel button and Information
13. 59. 4. MessageBox with Yes No Cancel button and Question iconMessageBox with Yes No Cancel button and Question icon
13. 59. 5. MessageBox OK and Cancel ButtonMessageBox OK and Cancel Button
13. 59. 6. MessageBox: Abort, Retry, Ignore buttons and Warning iconMessageBox: Abort, Retry, Ignore buttons and Warning icon
13. 59. 7. Set default button for MessageBoxSet default button for MessageBox
13. 59. 8. Displaying square root of 2 in dialog.
13. 59. 9. Return value from MessageBox
13. 59. 10. MessageBox Icon and ButtonMessageBox Icon and Button
13. 59. 11. Custom your MessageBoxCustom your MessageBox
13. 59. 12. Create MessageBox dynamicallyCreate MessageBox dynamically
w__w_w.j_a__va_2s__.co__m___ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.