G
Guest
Sorry for another query, but I'm have trouble handling a simple modal form.
The form (Form2) has only one textbox and two labels on it and I can show it
modally by including the following code in a button click event:
Private Sub Button1_Click(ByVal....)
Dim testDialog as New Form2
testDialog.Textbox2.Text = "Some text"
testDialog.ShowDialog(Me)
testDialog.Dispose
End Sub
When the Form shows, the text "Some text" appears in the textbox and I can
overwrite it using the keyboard. My problem is, how can I get the form to
close using either the Enter key, in which case the new textbox contents can
be passed back to the owner form (I guess this corresponds to the
DialogResult.OK response), or the Esc key, in which case the form closes
without passing the textbox contents?
I have tried using:
If testDialog.ShowDialog(Me) = System.Windows.Forms.Dialogresult.OK Then
..
ElseIf testDialog.ShowDialog(Me) =
System.Windows.Forms.Dialogresult.Cancel Then
..
End If
in place of the simple 'testDialog.ShowDialog(Me)' statement but the modal
form remains on-screen no matter what key is pressed.
Any comments would be gratefully received, as I need to use model forms
(some with and some without buttons on in addition to the labels and
textboxes) to maintain consistency with the VB4 version of our application.
P.S. Many thanks to Moshazu and Phill W. for responding to my RaiseEvent
query earlier today.
The form (Form2) has only one textbox and two labels on it and I can show it
modally by including the following code in a button click event:
Private Sub Button1_Click(ByVal....)
Dim testDialog as New Form2
testDialog.Textbox2.Text = "Some text"
testDialog.ShowDialog(Me)
testDialog.Dispose
End Sub
When the Form shows, the text "Some text" appears in the textbox and I can
overwrite it using the keyboard. My problem is, how can I get the form to
close using either the Enter key, in which case the new textbox contents can
be passed back to the owner form (I guess this corresponds to the
DialogResult.OK response), or the Esc key, in which case the form closes
without passing the textbox contents?
I have tried using:
If testDialog.ShowDialog(Me) = System.Windows.Forms.Dialogresult.OK Then
..
ElseIf testDialog.ShowDialog(Me) =
System.Windows.Forms.Dialogresult.Cancel Then
..
End If
in place of the simple 'testDialog.ShowDialog(Me)' statement but the modal
form remains on-screen no matter what key is pressed.
Any comments would be gratefully received, as I need to use model forms
(some with and some without buttons on in addition to the labels and
textboxes) to maintain consistency with the VB4 version of our application.
P.S. Many thanks to Moshazu and Phill W. for responding to my RaiseEvent
query earlier today.