Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 256
  • Last Modified:

Need to fire event on form close

in vb.net 2005 .  I have two forms open,  form1 and form2, is there a way to fire an event on form1 when form2 closes?
0
DustinHinkel
Asked:
DustinHinkel
  • 4
  • 3
1 Solution
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
Yes...in Form1, subscribe to Form2's closing event...

Does Form1 create Form2?
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
So something like...

Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim f2 As New Form2
        AddHandler f2.FormClosed, AddressOf Form2_FormClosed
        f2.Show()
    End Sub

    Private Sub Form2_FormClosed(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosedEventArgs)
        MessageBox.Show("Form2 was closed", "Message from Form1", MessageBoxButtons.OK, MessageBoxIcon.Information)
    End Sub

End Class
0
 
DustinHinkelAuthor Commented:
Form2 is opened from a command click from Form1, but not created from form1 if I understand you right.  Fairly new to this.  How do i "subscrive to Form2's closing event?
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
Mike TomlinsonMiddle School Assistant TeacherCommented:
See above...  ;)
0
 
DustinHinkelAuthor Commented:
Thanks that worked.  But when I put the code in my project i get an error going in design view.  It says:


 One or more errors encountered while loading the designer. The errors are listed below. Some errors can be fixed by rebuilding your project, while others may require code changes.

The type Form1 is made of several partial classes in the same file.
Hide    

at System.ComponentModel.Design.Serialization.CodeDomDesignerLoader.EnsureDocument(IDesignerSerializationManager manager)
at System.ComponentModel.Design.Serialization.CodeDomDesignerLoader.PerformLoad(IDesignerSerializationManager manager)
at Microsoft.VisualStudio.Design.Serialization.CodeDom.VSCodeDomDesignerLoader.PerformLoad(IDesignerSerializationManager serializationManager)
at System.ComponentModel.Design.Serialization.BasicDesignerLoader.BeginLoad(IDesignerLoaderHost host)


0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
Not sure what you did...

Make sure you have only ONE declaration for each form:

    Public Class Form1
        ...
    End Class
    Public Class Form1
        ...
    End Class

So in the above example, move everything from the second "Form1" class up into the first, and get rid of the second "Form1" class declaration.  Other than that, I'm not sure...
0
 
DustinHinkelAuthor Commented:
Sorry, I'm an idiot.  Learning would be impossible without people like  you.  Thanks
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now