VB.Net Tutorial/GUI/Custom Dialog

Материал из VB Эксперт
Перейти к: навигация, поиск

About Dialog

Imports System.Windows.Forms
public class AboutDialog
   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
    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
    Private components As System.ruponentModel.IContainer
    Friend WithEvents Button1 As System.Windows.Forms.Button
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.Button1 = New System.Windows.Forms.Button
        Me.SuspendLayout()
        "
        "Button1
        "
        Me.Button1.Font = New System.Drawing.Font("Microsoft Sans Serif", 9.75!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.Button1.Location = New System.Drawing.Point(160, 168)
        Me.Button1.Name = "Button1"
        Me.Button1.Size = New System.Drawing.Size(80, 32)
        Me.Button1.TabIndex = 0
        Me.Button1.Text = "About"
        "
        "Form1
        "
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.ClientSize = New System.Drawing.Size(292, 266)
        Me.Controls.Add(Me.Button1)
        Me.ResumeLayout(False)
    End Sub

    Private Sub showaboutBox()
        Dim aboutbox As New About
        aboutbox.ShowDialog(Me)
    End Sub
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        ShowAboutBox()
    End Sub
End Class

Public Class About
    Inherits System.Windows.Forms.Form
    Public Sub New()
        MyBase.New()
        InitializeComponent()
    End Sub
    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
    Private components As System.ruponentModel.IContainer
    Friend WithEvents Label1 As System.Windows.Forms.Label
    Friend WithEvents Label2 As System.Windows.Forms.Label
    Friend WithEvents LinkLabel1 As System.Windows.Forms.LinkLabel
    Friend WithEvents Button1 As System.Windows.Forms.Button
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.Label1 = New System.Windows.Forms.Label
        Me.Label2 = New System.Windows.Forms.Label
        Me.LinkLabel1 = New System.Windows.Forms.LinkLabel
        Me.Button1 = New System.Windows.Forms.Button
        Me.SuspendLayout()
        "
        "Label1
        "
        Me.Label1.Font = New System.Drawing.Font("Microsoft Sans Serif", 15.75!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.Label1.Location = New System.Drawing.Point(32, 24)
        Me.Label1.Name = "Label1"
        Me.Label1.Size = New System.Drawing.Size(152, 32)
        Me.Label1.TabIndex = 0
        Me.Label1.Text = "vbex.ru"
        "
        "Label2
        "
        Me.Label2.Font = New System.Drawing.Font("Microsoft Sans Serif", 12.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.Label2.Location = New System.Drawing.Point(32, 80)
        Me.Label2.Name = "Label2"
        Me.Label2.Size = New System.Drawing.Size(144, 24)
        Me.Label2.TabIndex = 1
        Me.Label2.Text = "version: 7.1.0391"
        "
        "LinkLabel1
        "
        Me.LinkLabel1.Font = New System.Drawing.Font("Microsoft Sans Serif", 12.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.LinkLabel1.Location = New System.Drawing.Point(32, 128)
        Me.LinkLabel1.Name = "LinkLabel1"
        Me.LinkLabel1.Size = New System.Drawing.Size(160, 32)
        Me.LinkLabel1.TabIndex = 2
        Me.LinkLabel1.TabStop = True
        Me.LinkLabel1.Text = "www.vbex.ru"
        "
        "Button1
        "
        Me.Button1.DialogResult = System.Windows.Forms.DialogResult.OK
        Me.Button1.Location = New System.Drawing.Point(176, 176)
        Me.Button1.Name = "Button1"
        Me.Button1.Size = New System.Drawing.Size(80, 32)
        Me.Button1.TabIndex = 3
        Me.Button1.Text = "OK"
        "
        "About
        "
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.ClientSize = New System.Drawing.Size(292, 266)
        Me.Controls.Add(Me.Button1)
        Me.Controls.Add(Me.LinkLabel1)
        Me.Controls.Add(Me.Label2)
        Me.Controls.Add(Me.Label1)
        Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog
        Me.MaximizeBox = False
        Me.MinimizeBox = False
        Me.Name = "About"
        Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent
        Me.Text = "About"
        Me.ResumeLayout(False)
    End Sub

    Private Sub LinkLabel1_LinkClicked(ByVal sender As System.Object, ByVal e As System.Windows.Forms.LinkLabelLinkClickedEventArgs) Handles LinkLabel1.LinkClicked
        System.Diagnostics.Process.Start("http://www.vbex.ru")
    End Sub
End Class

Create Dialog from Form

Imports System.Windows.Forms
Imports System.Drawing
Imports System.Drawing.Drawing2D
public class CreateDialogBaseOnForm
   public Shared Sub Main
        Application.Run(New Form1)
   End Sub
End class
Public Class DlgTest   
    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
    "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.
  Friend WithEvents btnOK As System.Windows.Forms.Button
  Friend WithEvents btnCancel As System.Windows.Forms.Button
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.btnOK = New System.Windows.Forms.Button()
Me.btnCancel = New System.Windows.Forms.Button()
Me.SuspendLayout()
"
"btnOK
"
Me.btnOK.DialogResult = System.Windows.Forms.DialogResult.OK
Me.btnOK.Location = New System.Drawing.Point(48, 152)
Me.btnOK.Name = "btnOK"
Me.btnOK.TabIndex = 0
Me.btnOK.Text = "Do It!"
"
"btnCancel
"
Me.btnCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel
Me.btnCancel.Location = New System.Drawing.Point(152, 152)
Me.btnCancel.Name = "btnCancel"
Me.btnCancel.TabIndex = 1
Me.btnCancel.Text = "Cancel"
"
"DlgTest
"
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(292, 273)
Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.btnCancel, Me.btnOK})
Me.Name = "DlgTest"
Me.Text = "dlg"
Me.ResumeLayout(False)
   End Sub
#End Region
  Private Sub btnOK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOK.Click
    DialogResult = DialogResult.OK
  End Sub
  Private Sub btnCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancel.Click
    DialogResult = DialogResult.Cancel
  End Sub
End Class

Public Class Form1
    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
    "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.
  Friend WithEvents btnCreate As System.Windows.Forms.Button
  Friend WithEvents lblReturn As System.Windows.Forms.Label
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.btnCreate = New System.Windows.Forms.Button()
Me.lblReturn = New System.Windows.Forms.Label()
Me.SuspendLayout()
"
"btnCreate
"
Me.btnCreate.Location = New System.Drawing.Point(96, 152)
Me.btnCreate.Name = "btnCreate"
Me.btnCreate.Size = New System.Drawing.Size(120, 23)
Me.btnCreate.TabIndex = 0
Me.btnCreate.Text = "Create Dialog Box"
"
"lblReturn
"
Me.lblReturn.Location = New System.Drawing.Point(96, 96)
Me.lblReturn.Name = "lblReturn"
Me.lblReturn.TabIndex = 1
"
"Form1
"
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(292, 273)
Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.lblReturn, Me.btnCreate})
Me.Name = "Form1"
Me.Text = "Form1"
Me.ResumeLayout(False)
   End Sub
#End Region
  Private Sub btnCreate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCreate.Click
    dim dlg as New DlgTest
    dlg.Text = "Dialog Test"
    dlg.FormBorderStyle = FormBorderStyle.FixedDialog
    dlg.BackColor = Color.Azure
    dlg.ControlBox = true
    dlg.MaximizeBox = false
    dlg.MinimizeBox = false
    dlg.ShowInTaskbar = false
    
    "dlg.Icon = new Icon(f.GetType(),"YourFile.ICO")
    dlg.Size = new Size(300,300)
    dlg.StartPosition = FormStartPosition.CenterScreen
    
    select case dlg.ShowDialog()
      case DialogResult.Abort
        lblReturn.Text = "Abort, Abort"
      case DialogResult.Cancel
        lblReturn.Text = "You have cancelled."
      case DialogResult.OK
        lblReturn.Text = "I"m OK, You"re OK"
      case else
        lblReturn.Text = "Whatever..."
    end select
    
  End Sub
End Class

Custom dialog with custom class

Imports System.Windows.Forms
public class CustomDialogWithCustomClass
   public Shared Sub Main
        Application.Run(New Form1)
   End Sub
End class
Public Class Form1
    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
    "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.
    Friend WithEvents Button1 As System.Windows.Forms.Button
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.Button1 = New System.Windows.Forms.Button
        Me.SuspendLayout()
        "
        "Button1
        "
        Me.Button1.Location = New System.Drawing.Point(104, 88)
        Me.Button1.Name = "Button1"
        Me.Button1.TabIndex = 0
        Me.Button1.Text = "Button1"
        "
        "Form1
        "
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.ClientSize = New System.Drawing.Size(292, 266)
        Me.Controls.Add(Me.Button1)
        Me.Name = "Form1"
        Me.Text = "Form1"
        Me.ResumeLayout(False)
    End Sub
#End Region
    Private Sub Button1_Click( _
            ByVal sender As System.Object, _
            ByVal e As System.EventArgs) _
            Handles Button1.Click
        Dim addr As New address
        Dim address As New addressDialog
        Dim Street As String = "124 "
        Dim City As String = "R"
        Dim Country As String = "VA"
        Dim PostalCode As String = "11111"
        addr.Street = Street
        addr.City = City
        addr.Country = Country
        addr.PostalCode = PostalCode
        address.Address = addr
        If address.ShowDialog = DialogResult.OK Then
            addr = address.Address
        End If
    End Sub
End Class
Public Class address
    Dim m_Street As String
    Dim m_City As String
    Dim m_PostalCode As String
    Dim m_Country As String
    Public Property Street() As String
        Get
            Return m_Street
        End Get
        Set(ByVal Value As String)
            m_Street = Value
        End Set
    End Property
    Public Property City() As String
        Get
            Return m_City
        End Get
        Set(ByVal Value As String)
            m_City = Value
        End Set
    End Property
    Public Property PostalCode() As String
        Get
            Return m_PostalCode
        End Get
        Set(ByVal Value As String)
            m_PostalCode = Value
        End Set
    End Property
    Public Property Country() As String
        Get
            Return m_Country
        End Get
        Set(ByVal Value As String)
            m_Country = Value
        End Set
    End Property

End Class
Public Class addressDialog
    Inherits System.Windows.Forms.Form
    Public Property Address() As address
        Get
            Dim newAddress As New address
            newAddress.City = txtCity.Text
            newAddress.Country = txtCountry.Text
            newAddress.PostalCode = txtPostalCode.Text
            newAddress.Street = txtStreet.Text
            Return newAddress
        End Get
        Set(ByVal Value As Address)
            txtCity.Text = Value.City
            txtCountry.Text = Value.Country
            txtPostalCode.Text = Value.PostalCode
            txtStreet.Text = Value.Street
        End Set
    End Property
#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
    "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.
    Friend WithEvents saveAddress As System.Windows.Forms.Button
    Friend WithEvents cancelAddress As System.Windows.Forms.Button
    Friend WithEvents Label1 As System.Windows.Forms.Label
    Friend WithEvents Label2 As System.Windows.Forms.Label
    Friend WithEvents Label3 As System.Windows.Forms.Label
    Friend WithEvents Label4 As System.Windows.Forms.Label
    Friend WithEvents txtStreet As System.Windows.Forms.TextBox
    Friend WithEvents txtCity As System.Windows.Forms.TextBox
    Friend WithEvents txtPostalCode As System.Windows.Forms.TextBox
    Friend WithEvents txtCountry As System.Windows.Forms.TextBox
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.saveAddress = New System.Windows.Forms.Button
        Me.cancelAddress = New System.Windows.Forms.Button
        Me.txtStreet = New System.Windows.Forms.TextBox
        Me.txtCity = New System.Windows.Forms.TextBox
        Me.txtPostalCode = New System.Windows.Forms.TextBox
        Me.txtCountry = New System.Windows.Forms.TextBox
        Me.Label1 = New System.Windows.Forms.Label
        Me.Label2 = New System.Windows.Forms.Label
        Me.Label3 = New System.Windows.Forms.Label
        Me.Label4 = New System.Windows.Forms.Label
        Me.SuspendLayout()
        "
        "saveAddress
        "
        Me.saveAddress.Anchor = CType((System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
        Me.saveAddress.DialogResult = System.Windows.Forms.DialogResult.OK
        Me.saveAddress.FlatStyle = System.Windows.Forms.FlatStyle.System
        Me.saveAddress.Location = New System.Drawing.Point(128, 120)
        Me.saveAddress.Name = "saveAddress"
        Me.saveAddress.TabIndex = 0
        Me.saveAddress.Text = "OK"
        "
        "cancelAddress
        "
        Me.cancelAddress.Anchor = CType((System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
        Me.cancelAddress.DialogResult = System.Windows.Forms.DialogResult.Cancel
        Me.cancelAddress.FlatStyle = System.Windows.Forms.FlatStyle.System
        Me.cancelAddress.Location = New System.Drawing.Point(208, 120)
        Me.cancelAddress.Name = "cancelAddress"
        Me.cancelAddress.TabIndex = 1
        Me.cancelAddress.Text = "Cancel"
        "
        "txtStreet
        "
        Me.txtStreet.Location = New System.Drawing.Point(80, 16)
        Me.txtStreet.Name = "txtStreet"
        Me.txtStreet.Size = New System.Drawing.Size(200, 20)
        Me.txtStreet.TabIndex = 2
        Me.txtStreet.Text = "txtStreet"
        "
        "txtCity
        "
        Me.txtCity.Location = New System.Drawing.Point(80, 40)
        Me.txtCity.Name = "txtCity"
        Me.txtCity.Size = New System.Drawing.Size(200, 20)
        Me.txtCity.TabIndex = 3
        Me.txtCity.Text = "txtCity"
        "
        "txtPostalCode
        "
        Me.txtPostalCode.Location = New System.Drawing.Point(80, 64)
        Me.txtPostalCode.Name = "txtPostalCode"
        Me.txtPostalCode.Size = New System.Drawing.Size(112, 20)
        Me.txtPostalCode.TabIndex = 4
        Me.txtPostalCode.Text = "txtPostalCode"
        "
        "txtCountry
        "
        Me.txtCountry.Location = New System.Drawing.Point(80, 88)
        Me.txtCountry.Name = "txtCountry"
        Me.txtCountry.Size = New System.Drawing.Size(200, 20)
        Me.txtCountry.TabIndex = 5
        Me.txtCountry.Text = "txtCountry"
        "
        "Label1
        "
        Me.Label1.AutoSize = True
        Me.Label1.Location = New System.Drawing.Point(39, 18)
        Me.Label1.Name = "Label1"
        Me.Label1.Size = New System.Drawing.Size(38, 16)
        Me.Label1.TabIndex = 6
        Me.Label1.Text = "Street:"
        "
        "Label2
        "
        Me.Label2.AutoSize = True
        Me.Label2.Location = New System.Drawing.Point(50, 42)
        Me.Label2.Name = "Label2"
        Me.Label2.Size = New System.Drawing.Size(27, 16)
        Me.Label2.TabIndex = 7
        Me.Label2.Text = "City:"
        "
        "Label3
        "
        Me.Label3.AutoSize = True
        Me.Label3.Location = New System.Drawing.Point(8, 66)
        Me.Label3.Name = "Label3"
        Me.Label3.Size = New System.Drawing.Size(69, 16)
        Me.Label3.TabIndex = 8
        Me.Label3.Text = "Postal Code:"
        "
        "Label4
        "
        Me.Label4.AutoSize = True
        Me.Label4.Location = New System.Drawing.Point(33, 90)
        Me.Label4.Name = "Label4"
        Me.Label4.Size = New System.Drawing.Size(44, 16)
        Me.Label4.TabIndex = 9
        Me.Label4.Text = "Country"
        "
        "addressDialog
        "
        Me.AcceptButton = Me.saveAddress
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.CancelButton = Me.cancelAddress
        Me.ClientSize = New System.Drawing.Size(292, 152)
        Me.Controls.Add(Me.Label4)
        Me.Controls.Add(Me.Label3)
        Me.Controls.Add(Me.Label2)
        Me.Controls.Add(Me.Label1)
        Me.Controls.Add(Me.txtCountry)
        Me.Controls.Add(Me.txtPostalCode)
        Me.Controls.Add(Me.txtCity)
        Me.Controls.Add(Me.txtStreet)
        Me.Controls.Add(Me.cancelAddress)
        Me.Controls.Add(Me.saveAddress)
        Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog
        Me.MaximizeBox = False
        Me.MinimizeBox = False
        Me.Name = "addressDialog"
        Me.Text = "Address Dialog"
        Me.ResumeLayout(False)
    End Sub
#End Region
    Private Sub saveAddress_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles saveAddress.Click
        Me.Close()
    End Sub
    Private Sub cancelAddress_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cancelAddress.Click
        Me.Close()
    End Sub
End Class

Dialog apply method

Imports System.Drawing
Imports System.Drawing.Drawing2D
Imports System.Windows.Forms
public class DialogApplyMethod
   public Shared Sub Main
        Application.Run(New Form1)
   End Sub
End class

Public Class Form1
    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
    "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.
  Friend WithEvents btnCreate As System.Windows.Forms.Button
  Friend WithEvents lblReturn As System.Windows.Forms.Label
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.btnCreate = New System.Windows.Forms.Button()
Me.lblReturn = New System.Windows.Forms.Label()
Me.SuspendLayout()
"
"btnCreate
"
Me.btnCreate.Location = New System.Drawing.Point(72, 144)
Me.btnCreate.Name = "btnCreate"
Me.btnCreate.Size = New System.Drawing.Size(152, 23)
Me.btnCreate.TabIndex = 0
Me.btnCreate.Text = "Create Dialog Box"
"
"lblReturn
"
Me.lblReturn.Location = New System.Drawing.Point(88, 72)
Me.lblReturn.Name = "lblReturn"
Me.lblReturn.TabIndex = 1
"
"Form1
"
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(292, 273)
Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.lblReturn, Me.btnCreate})
Me.Name = "Form1"
Me.Text = "Form1"
Me.ResumeLayout(False)
   End Sub
#End Region
  public sub UpdateLabel(str as String)
    lblReturn.Text = str
  end sub
  Private Sub btnCreate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCreate.Click
    dim dlg as new DialogDemo( me ) 
    dlg.EnableApplyButton = false
    dlg.ShowDialog()
    
    if dlg.DialogResult = DialogResult.OK then
      lblReturn.Text = dlg.TextOut
    else
      lblReturn.Text = dlg.DialogResult.ToString()
    end if
  End Sub
End Class
public class DialogDemo 
      inherits Form
  dim btnApply as Button
  dim txt as TextBox
  dim f as Form1
  
  public sub new (f as Form1)
        myBase.New
    me.f = f
    FormBorderStyle = FormBorderStyle.FixedDialog
    ControlBox = false
    MaximizeBox = false
    MinimizeBox = false
    ShowInTaskbar = false
    Size = new Size(400,200)
    StartPosition = FormStartPosition.CenterScreen
    dim btnOK as New Button
    btnOK.Text = "OK"
    btnOK.DialogResult = DialogResult.OK
    btnOK.Location = new Point(50,50)
    Controls.Add(btnOK)
    
    btnApply = new Button()
    btnApply.Text = "Apply"
    btnApply.Location = new Point(150,50)
    btnApply.Enabled = false
    AddHandler btnApply.Click, AddressOf ApplyOnClick
    Controls.Add(btnApply)
    
    dim btnCancel as new Button()
    btnCancel.Text = "Cancel"
    btnCancel.DialogResult = DialogResult.Cancel
    btnCancel.Location = new Point(250,50)
    Controls.Add(btnCancel)
    txt = new TextBox()
    txt.Size = new Size(100,15)
    txt.Location = new Point(150,15)
    AddHandler txt.TextChanged, AddressOf TextBoxChanged
    Controls.Add(txt)
    
  end sub
  private sub ApplyOnClick(sender as Object, e as EventArgs)
    f.UpdateLabel(txt.Text)
    EnableApplyButton = false
  end sub
  
  private sub TextBoxChanged(sender as Object, e as EventArgs)
    dim txt as TextBox = CType(sender,TextBox)
    dim dlg as DialogDemo = CType(txt.Parent,DialogDemo)
    dlg.EnableApplyButton = true  
  end sub
  public property EnableApplyButton as Boolean
    get 
      return btnApply.Enabled
    end get
    set
      btnApply.Enabled = value 
    end set
  end property
  
  public ReadOnly property TextOut as string
    get
      return txt.Text 
    end get
  end property
end class

Dialog with properties

Imports System.Windows.Forms
public class DialogWithProperties
   public Shared Sub Main
        Application.Run(New Form1)
   End Sub
End class
Public Class Form1
    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
    "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.
    Friend WithEvents Button1 As System.Windows.Forms.Button
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.Button1 = New System.Windows.Forms.Button
        Me.SuspendLayout()
        "
        "Button1
        "
        Me.Button1.Location = New System.Drawing.Point(104, 88)
        Me.Button1.Name = "Button1"
        Me.Button1.TabIndex = 0
        Me.Button1.Text = "Button1"
        "
        "Form1
        "
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.ClientSize = New System.Drawing.Size(292, 266)
        Me.Controls.Add(Me.Button1)
        Me.Name = "Form1"
        Me.Text = "Form1"
        Me.ResumeLayout(False)
    End Sub
#End Region
    Private Sub Button1_Click( _
            ByVal sender As System.Object, _
            ByVal e As System.EventArgs) _
            Handles Button1.Click
        Dim address As New addressDialog
        Dim Street As String = "aaaa"
        Dim City As String = "wwww"
        Dim Country As String = "qqqq"
        Dim PostalCode As String = "93333"
        address.Street = Street
        address.City = City
        address.Country = Country
        address.PostalCode = PostalCode
        If address.ShowDialog = DialogResult.OK Then
            Street = address.Street
            City = address.City
            Country = address.Country
            PostalCode = address.PostalCode
        End If
    End Sub
End Class
Public Class addressDialog
    Inherits System.Windows.Forms.Form
    Public Property Street() As String
        Get
            Return Me.txtStreet.Text
        End Get
        Set(ByVal Value As String)
            Me.txtStreet.Text = Value
        End Set
    End Property
    Public Property City() As String
        Get
            Return Me.txtCity.Text
        End Get
        Set(ByVal Value As String)
            Me.txtCity.Text = Value
        End Set
    End Property
    Public Property PostalCode() As String
        Get
            Return Me.txtPostalCode.Text
        End Get
        Set(ByVal Value As String)
            Me.txtPostalCode.Text = Value
        End Set
    End Property
    Public Property Country() As String
        Get
            Return Me.txtCountry.Text
        End Get
        Set(ByVal Value As String)
            Me.txtCountry.Text = Value
        End Set
    End Property
#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
    "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.
    Friend WithEvents saveAddress As System.Windows.Forms.Button
    Friend WithEvents cancelAddress As System.Windows.Forms.Button
    Friend WithEvents Label1 As System.Windows.Forms.Label
    Friend WithEvents Label2 As System.Windows.Forms.Label
    Friend WithEvents Label3 As System.Windows.Forms.Label
    Friend WithEvents Label4 As System.Windows.Forms.Label
    Friend WithEvents txtStreet As System.Windows.Forms.TextBox
    Friend WithEvents txtCity As System.Windows.Forms.TextBox
    Friend WithEvents txtPostalCode As System.Windows.Forms.TextBox
    Friend WithEvents txtCountry As System.Windows.Forms.TextBox
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.saveAddress = New System.Windows.Forms.Button
        Me.cancelAddress = New System.Windows.Forms.Button
        Me.txtStreet = New System.Windows.Forms.TextBox
        Me.txtCity = New System.Windows.Forms.TextBox
        Me.txtPostalCode = New System.Windows.Forms.TextBox
        Me.txtCountry = New System.Windows.Forms.TextBox
        Me.Label1 = New System.Windows.Forms.Label
        Me.Label2 = New System.Windows.Forms.Label
        Me.Label3 = New System.Windows.Forms.Label
        Me.Label4 = New System.Windows.Forms.Label
        Me.SuspendLayout()
        "
        "saveAddress
        "
        Me.saveAddress.Anchor = CType((System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
        Me.saveAddress.DialogResult = System.Windows.Forms.DialogResult.OK
        Me.saveAddress.FlatStyle = System.Windows.Forms.FlatStyle.System
        Me.saveAddress.Location = New System.Drawing.Point(128, 120)
        Me.saveAddress.Name = "saveAddress"
        Me.saveAddress.TabIndex = 0
        Me.saveAddress.Text = "OK"
        "
        "cancelAddress
        "
        Me.cancelAddress.Anchor = CType((System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
        Me.cancelAddress.DialogResult = System.Windows.Forms.DialogResult.Cancel
        Me.cancelAddress.FlatStyle = System.Windows.Forms.FlatStyle.System
        Me.cancelAddress.Location = New System.Drawing.Point(208, 120)
        Me.cancelAddress.Name = "cancelAddress"
        Me.cancelAddress.TabIndex = 1
        Me.cancelAddress.Text = "Cancel"
        "
        "txtStreet
        "
        Me.txtStreet.Location = New System.Drawing.Point(80, 16)
        Me.txtStreet.Name = "txtStreet"
        Me.txtStreet.Size = New System.Drawing.Size(200, 20)
        Me.txtStreet.TabIndex = 2
        Me.txtStreet.Text = "txtStreet"
        "
        "txtCity
        "
        Me.txtCity.Location = New System.Drawing.Point(80, 40)
        Me.txtCity.Name = "txtCity"
        Me.txtCity.Size = New System.Drawing.Size(200, 20)
        Me.txtCity.TabIndex = 3
        Me.txtCity.Text = "txtCity"
        "
        "txtPostalCode
        "
        Me.txtPostalCode.Location = New System.Drawing.Point(80, 64)
        Me.txtPostalCode.Name = "txtPostalCode"
        Me.txtPostalCode.Size = New System.Drawing.Size(112, 20)
        Me.txtPostalCode.TabIndex = 4
        Me.txtPostalCode.Text = "txtPostalCode"
        "
        "txtCountry
        "
        Me.txtCountry.Location = New System.Drawing.Point(80, 88)
        Me.txtCountry.Name = "txtCountry"
        Me.txtCountry.Size = New System.Drawing.Size(200, 20)
        Me.txtCountry.TabIndex = 5
        Me.txtCountry.Text = "txtCountry"
        "
        "Label1
        "
        Me.Label1.AutoSize = True
        Me.Label1.Location = New System.Drawing.Point(39, 18)
        Me.Label1.Name = "Label1"
        Me.Label1.Size = New System.Drawing.Size(38, 16)
        Me.Label1.TabIndex = 6
        Me.Label1.Text = "Street:"
        "
        "Label2
        "
        Me.Label2.AutoSize = True
        Me.Label2.Location = New System.Drawing.Point(50, 42)
        Me.Label2.Name = "Label2"
        Me.Label2.Size = New System.Drawing.Size(27, 16)
        Me.Label2.TabIndex = 7
        Me.Label2.Text = "City:"
        "
        "Label3
        "
        Me.Label3.AutoSize = True
        Me.Label3.Location = New System.Drawing.Point(8, 66)
        Me.Label3.Name = "Label3"
        Me.Label3.Size = New System.Drawing.Size(69, 16)
        Me.Label3.TabIndex = 8
        Me.Label3.Text = "Postal Code:"
        "
        "Label4
        "
        Me.Label4.AutoSize = True
        Me.Label4.Location = New System.Drawing.Point(33, 90)
        Me.Label4.Name = "Label4"
        Me.Label4.Size = New System.Drawing.Size(44, 16)
        Me.Label4.TabIndex = 9
        Me.Label4.Text = "Country"
        "
        "addressDialog
        "
        Me.AcceptButton = Me.saveAddress
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.CancelButton = Me.cancelAddress
        Me.ClientSize = New System.Drawing.Size(292, 152)
        Me.Controls.Add(Me.Label4)
        Me.Controls.Add(Me.Label3)
        Me.Controls.Add(Me.Label2)
        Me.Controls.Add(Me.Label1)
        Me.Controls.Add(Me.txtCountry)
        Me.Controls.Add(Me.txtPostalCode)
        Me.Controls.Add(Me.txtCity)
        Me.Controls.Add(Me.txtStreet)
        Me.Controls.Add(Me.cancelAddress)
        Me.Controls.Add(Me.saveAddress)
        Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog
        Me.MaximizeBox = False
        Me.MinimizeBox = False
        Me.Name = "addressDialog"
        Me.Text = "Address Dialog"
        Me.ResumeLayout(False)
    End Sub
#End Region
    Private Sub saveAddress_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles saveAddress.Click
        Me.Close()
    End Sub
    Private Sub cancelAddress_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cancelAddress.Click
        Me.Close()
    End Sub
End Class

Get Custom dialog returning value

Imports System.ruponentModel
Imports System.Windows.Forms
public class CustomDialogEmployee
   public Shared Sub Main
        Application.Run(New Form1)
   End Sub
End class
Public Class Form1
    Private Sub btnShowDialog_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnShowDialog.Click
        Dim dlg As New dlgEmployee
        
        If dlg.ShowDialog() = Windows.Forms.DialogResult.OK Then
            MessageBox.Show( _
                dlg.txtFirstName.Text & " " & _
                dlg.txtLastName.Text)
        Else
            MessageBox.Show("Canceled")
        End If
    End Sub
End Class
<Global.Microsoft.VisualBasic.rupilerServices.DesignerGenerated()> _
Partial Public Class Form1
    Inherits System.Windows.Forms.Form
    "Form overrides dispose to clean up the component list.
    <System.Diagnostics.DebuggerNonUserCode()> _
    Protected Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing AndAlso components IsNot Nothing Then
            components.Dispose()
        End If
        MyBase.Dispose(disposing)
    End Sub
    "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.btnShowDialog = New System.Windows.Forms.Button
        Me.SuspendLayout()
        "
        "btnShowDialog
        "
        Me.btnShowDialog.Location = New System.Drawing.Point(56, 32)
        Me.btnShowDialog.Name = "btnShowDialog"
        Me.btnShowDialog.Size = New System.Drawing.Size(80, 23)
        Me.btnShowDialog.TabIndex = 1
        Me.btnShowDialog.Text = "Show Dialog"
        "
        "Form1
        "
        Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
        Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
        Me.ClientSize = New System.Drawing.Size(199, 93)
        Me.Controls.Add(Me.btnShowDialog)
        Me.Name = "Form1"
        Me.Text = "CustomDialog"
        Me.ResumeLayout(False)
    End Sub
    Friend WithEvents btnShowDialog As System.Windows.Forms.Button
End Class
<Global.Microsoft.VisualBasic.rupilerServices.DesignerGenerated()> _
Partial Public Class dlgEmployee
    Inherits System.Windows.Forms.Form
    "Form overrides dispose to clean up the component list.
    <System.Diagnostics.DebuggerNonUserCode()> _
    Protected Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing AndAlso components IsNot Nothing Then
            components.Dispose()
        End If
        MyBase.Dispose(disposing)
    End Sub
    "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.txtLastName = New System.Windows.Forms.TextBox
        Me.Label2 = New System.Windows.Forms.Label
        Me.btnCancel = New System.Windows.Forms.Button
        Me.btnOk = New System.Windows.Forms.Button
        Me.txtFirstName = New System.Windows.Forms.TextBox
        Me.Label1 = New System.Windows.Forms.Label
        Me.SuspendLayout()
        "
        "txtLastName
        "
        Me.txtLastName.Location = New System.Drawing.Point(72, 33)
        Me.txtLastName.Name = "txtLastName"
        Me.txtLastName.Size = New System.Drawing.Size(168, 20)
        Me.txtLastName.TabIndex = 7
        "
        "Label2
        "
        Me.Label2.AutoSize = True
        Me.Label2.Location = New System.Drawing.Point(8, 33)
        Me.Label2.Name = "Label2"
        Me.Label2.Size = New System.Drawing.Size(58, 13)
        Me.Label2.TabIndex = 10
        Me.Label2.Text = "Last Name"
        "
        "btnCancel
        "
        Me.btnCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel
        Me.btnCancel.Location = New System.Drawing.Point(256, 49)
        Me.btnCancel.Name = "btnCancel"
        Me.btnCancel.Size = New System.Drawing.Size(56, 24)
        Me.btnCancel.TabIndex = 9
        Me.btnCancel.Text = "Cancel"
        "
        "btnOk
        "
        Me.btnOk.DialogResult = System.Windows.Forms.DialogResult.OK
        Me.btnOk.Location = New System.Drawing.Point(256, 9)
        Me.btnOk.Name = "btnOk"
        Me.btnOk.Size = New System.Drawing.Size(56, 24)
        Me.btnOk.TabIndex = 8
        Me.btnOk.Text = "OK"
        "
        "txtFirstName
        "
        Me.txtFirstName.Location = New System.Drawing.Point(72, 9)
        Me.txtFirstName.Name = "txtFirstName"
        Me.txtFirstName.Size = New System.Drawing.Size(168, 20)
        Me.txtFirstName.TabIndex = 5
        "
        "Label1
        "
        Me.Label1.AutoSize = True
        Me.Label1.Location = New System.Drawing.Point(8, 9)
        Me.Label1.Name = "Label1"
        Me.Label1.Size = New System.Drawing.Size(57, 13)
        Me.Label1.TabIndex = 6
        Me.Label1.Text = "First Name"
        "
        "dlgEmployee
        "
        Me.AcceptButton = Me.btnOk
        Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
        Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
        Me.CancelButton = Me.btnOk
        Me.ClientSize = New System.Drawing.Size(320, 82)
        Me.Controls.Add(Me.txtLastName)
        Me.Controls.Add(Me.Label2)
        Me.Controls.Add(Me.btnCancel)
        Me.Controls.Add(Me.btnOk)
        Me.Controls.Add(Me.txtFirstName)
        Me.Controls.Add(Me.Label1)
        Me.Name = "dlgEmployee"
        Me.Text = "Enter Value"
        Me.ResumeLayout(False)
        Me.PerformLayout()
    End Sub
    Friend WithEvents txtLastName As System.Windows.Forms.TextBox
    Friend WithEvents Label2 As System.Windows.Forms.Label
    Friend WithEvents btnCancel As System.Windows.Forms.Button
    Friend WithEvents btnOk As System.Windows.Forms.Button
    Friend WithEvents txtFirstName As System.Windows.Forms.TextBox
    Friend WithEvents Label1 As System.Windows.Forms.Label
End Class

Login Dialog

Imports System.Windows.Forms
public class LoginDialog
   public Shared Sub Main
        Application.Run(New Form1)
   End Sub
End class
Public Class Form1
    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
    "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()
        components = New System.ruponentModel.Container()
        Me.Text = "Form1"
    End Sub
#End Region
  Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
    Dim frmLogon As New LogonDialog()
    Dim success As Boolean = False
    Dim errorMessage As String
    If frmLogon.ShowDialog() = DialogResult.OK Then
      If frmLogon.txtUserid.Text = "Joe" Then
        If frmLogon.txtPassword.Text = "password" Then
          success = True
        Else
          errorMessage = "Invalid Password!"
        End If
      Else
        errorMessage = "Invalid User ID!"
      End If
    Else
      errorMessage = "Logon Attempt Cancelled"
    End If
    If Not success Then
      MessageBox.Show(errorMessage, "Logon Failed", MessageBoxButtons.OK, MessageBoxIcon.Error)
      Me.Close()
    End If
  End Sub
End Class
Public Class LogonDialog
    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 btnOK As System.Windows.Forms.Button
  Friend WithEvents btnCancel As System.Windows.Forms.Button
  Friend WithEvents lblUserid As System.Windows.Forms.Label
  Friend WithEvents lblPassword As System.Windows.Forms.Label
  Friend WithEvents txtUserid As System.Windows.Forms.TextBox
  Friend WithEvents txtPassword As System.Windows.Forms.TextBox
    "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.btnOK = New System.Windows.Forms.Button()
    Me.btnCancel = New System.Windows.Forms.Button()
    Me.txtUserid = New System.Windows.Forms.TextBox()
    Me.txtPassword = New System.Windows.Forms.TextBox()
    Me.lblUserid = New System.Windows.Forms.Label()
    Me.lblPassword = New System.Windows.Forms.Label()
    Me.SuspendLayout()
    "
    "btnOK
    "
    Me.btnOK.Location = New System.Drawing.Point(128, 64)
    Me.btnOK.Name = "btnOK"
    Me.btnOK.TabIndex = 0
    Me.btnOK.Text = "OK"
    "
    "btnCancel
    "
    Me.btnCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel
    Me.btnCancel.Location = New System.Drawing.Point(205, 64)
    Me.btnCancel.Name = "btnCancel"
    Me.btnCancel.TabIndex = 1
    Me.btnCancel.Text = "Cancel"
    "
    "txtUserid
    "
    Me.txtUserid.Location = New System.Drawing.Point(72, 8)
    Me.txtUserid.Name = "txtUserid"
    Me.txtUserid.Size = New System.Drawing.Size(208, 20)
    Me.txtUserid.TabIndex = 2
    Me.txtUserid.Text = "Joe"
    "
    "txtPassword
    "
    Me.txtPassword.Location = New System.Drawing.Point(72, 32)
    Me.txtPassword.Name = "txtPassword"
    Me.txtPassword.PasswordChar = ChrW(42)
    Me.txtPassword.Size = New System.Drawing.Size(208, 20)
    Me.txtPassword.TabIndex = 3
    Me.txtPassword.Text = "password"
    "
    "lblUserid
    "
    Me.lblUserid.AutoSize = True
    Me.lblUserid.Location = New System.Drawing.Point(8, 12)
    Me.lblUserid.Name = "lblUserid"
    Me.lblUserid.Size = New System.Drawing.Size(43, 13)
    Me.lblUserid.TabIndex = 4
    Me.lblUserid.Text = "UserID:"
    "
    "lblPassword
    "
    Me.lblPassword.AutoSize = True
    Me.lblPassword.Location = New System.Drawing.Point(8, 36)
    Me.lblPassword.Name = "lblPassword"
    Me.lblPassword.Size = New System.Drawing.Size(57, 13)
    Me.lblPassword.TabIndex = 5
    Me.lblPassword.Text = "Password:"
    "
    "LogonDialog
    "
    Me.AcceptButton = Me.btnOK
    Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
    Me.CancelButton = Me.btnCancel
    Me.ClientSize = New System.Drawing.Size(290, 95)
    Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.lblPassword, Me.lblUserid, Me.txtPassword, Me.txtUserid, Me.btnCancel, Me.btnOK})
    Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog
    Me.MaximizeBox = False
    Me.MinimizeBox = False
    Me.Name = "LogonDialog"
    Me.Text = "Logon"
    Me.ResumeLayout(False)
  End Sub
#End Region
  Private Sub btnOK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOK.Click
    Dim sUserID As String
    Dim sPassword As String
    sUserID = txtUserid.Text
    sPassword = txtPassword.Text
    If sUserID.Trim() = "" Then
      MessageBox.Show("UserID cannot be blank.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
      txtUserid.Select()
    Else
      If sPassword.Trim() = "" Then
        MessageBox.Show("Password cannot be blank.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
        txtPassword.Select()
      Else
        Me.DialogResult = DialogResult.OK
      End If
    End If
  End Sub
End Class

User defined Dialog

Imports System.Windows.Forms
public class UseDefineDialog
   public Shared Sub Main
        Application.Run(New Form1)
   End Sub
End class
Public Class Form1
    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
    Private WithEvents btnNewCaption As System.Windows.Forms.Button
    "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.btnNewCaption = New System.Windows.Forms.Button()
        Me.SuspendLayout()
        "
        "btnNewCaption
        "
        Me.btnNewCaption.Location = New System.Drawing.Point(106, 120)
        Me.btnNewCaption.Name = "btnNewCaption"
        Me.btnNewCaption.Size = New System.Drawing.Size(80, 32)
        Me.btnNewCaption.TabIndex = 0
        Me.btnNewCaption.Text = "New Caption"
        "
        "Form1
        "
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.ClientSize = New System.Drawing.Size(292, 273)
        Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.btnNewCaption})
        Me.Name = "Form1"
        Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
        Me.Text = "Form1"
        Me.ResumeLayout(False)
    End Sub
#End Region
    Private Sub btnNewCaption_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNewCaption.Click
        Dim frmCaption As New Form2()
        frmCaption.ShowDialog()
        If frmCaption.DialogResult = DialogResult.OK Then
            Me.Text = frmCaption.Caption
        End If
    End Sub
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        
    End Sub
End Class


Public Class Form2
    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
    Private WithEvents btnOK As System.Windows.Forms.Button
    Private WithEvents btnCancel As System.Windows.Forms.Button
    Private WithEvents txtNewCaption As System.Windows.Forms.TextBox
    "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.DebuggerStepThroughAttribute()> Private Sub InitializeComponent()
        Me.btnCancel = New System.Windows.Forms.Button()
        Me.txtNewCaption = New System.Windows.Forms.TextBox()
        Me.btnOK = New System.Windows.Forms.Button()
        Me.SuspendLayout()
        "
        "btnCancel
        "
        Me.btnCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel
        Me.btnCancel.Location = New System.Drawing.Point(141, 80)
        Me.btnCancel.Name = "btnCancel"
        Me.btnCancel.Size = New System.Drawing.Size(72, 32)
        Me.btnCancel.TabIndex = 2
        Me.btnCancel.Text = "Cancel"
        "
        "txtNewCaption
        "
        Me.txtNewCaption.Location = New System.Drawing.Point(73, 32)
        Me.txtNewCaption.Name = "txtNewCaption"
        Me.txtNewCaption.Size = New System.Drawing.Size(120, 20)
        Me.txtNewCaption.TabIndex = 1
        Me.txtNewCaption.Text = ""
        "
        "btnOK
        "
        Me.btnOK.DialogResult = System.Windows.Forms.DialogResult.OK
        Me.btnOK.Location = New System.Drawing.Point(53, 80)
        Me.btnOK.Name = "btnOK"
        Me.btnOK.Size = New System.Drawing.Size(72, 32)
        Me.btnOK.TabIndex = 0
        Me.btnOK.Text = "OK"
        "
        "Form2
        "
        Me.AcceptButton = Me.btnOK
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.CancelButton = Me.btnCancel
        Me.ClientSize = New System.Drawing.Size(266, 154)
        Me.ControlBox = False
        Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.btnCancel, Me.txtNewCaption, Me.btnOK})
        Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog
        Me.Name = "Form2"
        Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent
        Me.Text = "Dialog"
        Me.ResumeLayout(False)
    End Sub
#End Region
    Public Property Caption() As String
        Get
            Caption = txtNewCaption.Text
        End Get
        Set(ByVal Value As String)
        End Set
    End Property

End Class