Lukasz said:
How should I do that? Can You give some code sample?
Part of this work is in the designer, so I am showing form and button
properties as well.
- Lee
Public Class DialogForm
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.ComponentModel.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
Friend WithEvents TextBox1 As System.Windows.Forms.TextBox
Friend WithEvents Label1 As System.Windows.Forms.Label
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()
Me.btnOK = New System.Windows.Forms.Button
Me.btnCancel = New System.Windows.Forms.Button
Me.TextBox1 = New System.Windows.Forms.TextBox
Me.Label1 = New System.Windows.Forms.Label
Me.SuspendLayout()
'
'btnOK
'
Me.btnOK.DialogResult = System.Windows.Forms.DialogResult.OK
Me.btnOK.Location = New System.Drawing.Point(16, 216)
Me.btnOK.Name = "btnOK"
Me.btnOK.Size = New System.Drawing.Size(72, 32)
Me.btnOK.TabIndex = 0
Me.btnOK.Text = "OK"
'
'btnCancel
'
Me.btnCancel.DialogResult =
System.Windows.Forms.DialogResult.Cancel
Me.btnCancel.Location = New System.Drawing.Point(200, 224)
Me.btnCancel.Name = "btnCancel"
Me.btnCancel.Size = New System.Drawing.Size(72, 32)
Me.btnCancel.TabIndex = 1
Me.btnCancel.Text = "CANCEL"
'
'TextBox1
'
Me.TextBox1.Location = New System.Drawing.Point(96, 128)
Me.TextBox1.Name = "TextBox1"
Me.TextBox1.Size = New System.Drawing.Size(88, 20)
Me.TextBox1.TabIndex = 2
Me.TextBox1.Text = ""
'
'Label1
'
Me.Label1.Location = New System.Drawing.Point(64, 88)
Me.Label1.Name = "Label1"
Me.Label1.Size = New System.Drawing.Size(144, 32)
Me.Label1.TabIndex = 3
Me.Label1.Text = "Enter a number from 1 to 3"
'
'DialogForm
'
Me.AcceptButton = Me.btnOK
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.CancelButton = Me.btnCancel
Me.ClientSize = New System.Drawing.Size(292, 273)
Me.Controls.Add(Me.Label1)
Me.Controls.Add(Me.TextBox1)
Me.Controls.Add(Me.btnCancel)
Me.Controls.Add(Me.btnOK)
Me.Name = "DialogForm"
Me.Text = "DialogForm"
Me.ResumeLayout(False)
End Sub
#End Region
Private Sub DialogForm_Closing( _
ByVal sender As Object, _
ByVal e As System.ComponentModel.CancelEventArgs) _
Handles MyBase.Closing
If Me.DialogResult = DialogResult.OK Then
If Not IsNumeric(Me.TextBox1.Text) Then
If MsgBox( _
"Not a number. Retry to resume editing.", _
MsgBoxStyle.RetryCancel) = MsgBoxResult.Retry Then
e.Cancel = True
Return
End If
End If
Dim v As Integer = CInt(Me.TextBox1.Text)
If (v < 1) Or (v > 3) Then
If MsgBox( _
"Must be 1-3. Retry to resume editing.", _
MsgBoxStyle.RetryCancel) = MsgBoxResult.Retry Then
e.Cancel = True
Return
End If
End If
' APPLY THE VALUE OF V HERE TO WHAT EVER
' BECAUSE YOU KNOW IT IS VALID NOW
' CANCEL OR CLOSING FORM WON'T GET TO HERE
' RETRY WILL KEEP THE FORM OPEN
End If
End Sub
End Class