vb.net modal form

  • Thread starter Thread starter Chris Thunell
  • Start date Start date
C

Chris Thunell

I have a form with information on it, when a button is clicked, another form
is opened with the following code:
Dim myForm As New ReqVendorSelect
myForm.Visible = True

Once i'm done manipulating some data on the 2nd form, the 2nd form is closed
and the original form is now visible. Is there anyway for the original form
to know when the newly created form is closed?

Chris Thunell
(e-mail address removed)
 
Chris Thunell said:
I have a form with information on it, when a button is clicked,
another form is opened with the following code:
Dim myForm As New ReqVendorSelect
myForm.Visible = True

Once i'm done manipulating some data on the 2nd form, the 2nd form is
closed and the original form is now visible. Is there anyway for the
original form to know when the newly created form is closed?

Is there a reason why you don't show the form modally? (as mentioned in the
subject line)

Dim myForm As New ReqVendorSelect
myForm.ShowDialog
 
Hi Chris,

Thanks for your post. I agree with Armin and strongly recommend you use
ShowDialog to display the form modally. In addition, the original form is
able to be notified when the newly created form is closed in the Closed
event handler of the new form. Please refer to the following code snippet:

'------------------------code snippet---------------------------
Public Class Form1
Inherits System.Windows.Forms.Form

Dim WithEvents myForm As New ReqVendorSelect

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
myForm.Visible = True
End Sub

Private Sub myForm_Closed(ByVal sender As Object, ByVal e As
System.EventArgs) Handles myForm.Closed
MsgBox("myForm closed")
End Sub
End Class
'--------------------------end of------------------------------------

Hope this helps.

Regards,

HuangTM
Microsoft Online Partner Support
MCSE/MCSD

Get Secure! -- www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
Back
Top