Click here to Skip to main content
15,885,278 members
Please Sign up or sign in to vote.
1.50/5 (2 votes)
See more:
I have two project (Project1 and Project2)
I have add project2 into Project1 and Also add Reference of Project2 to Project1.

How to check a status of Project2.Form1..
Actually I want to track Project2.Form1 during the time of closing...
means when Project2.Form1 geeting close
A messagebox will apprear... to me with message... Form is closing...
But This message box I want to run from Project1.Form1.
In Project1.Form1. I have did the following things.

Imports Project2.Form1
Dim Prj2frm as Project2.Form1

Now I want track its closing status....

If Prj2frm getting close... then
Messagebox.show("Form is closing")
else
nothing
endif

please help....
Posted
Comments
Sergey Alexandrovich Kryukov 6-Nov-13 11:05am    
First of all, is it System.Windows.Forms.Form, or something else? When it comes to UI, you should always tag the UI library/framework or application type you use, or provide full type names.

What kind of project (a class library, application)? Why would you ever use a form of one in another. This is quite possible and sometimes useful, but why? And you don't work with projects during runtime, there are only assemblies and modules...

—SA
Member 10279246 7-Nov-13 6:51am    
Sir, question is simple... I have add Project2 into Project1... I want to make an event... when Project2.Form1 is closing.... then Project1 tell me... it is closed... I don't want to put messagebox in Project2.Form1 on closing.... I want to define that messagebox in Project1.

Your problem is not well formulated, but, most likely, you need this:
http://msdn.microsoft.com/en-us/library/system.windows.forms.form.formclosing%28v=vs.110%29.aspx[^].

Note that this event allows you to cancel closing, so you can do it depending on condition:
http://msdn.microsoft.com/en-us/library/system.windows.forms.formclosingeventargs%28v=vs.110%29.aspx[^],
http://msdn.microsoft.com/en-us/library/system.windows.forms.formclosingeventargs.closereason%28v=vs.110%29.aspx[^],
http://msdn.microsoft.com/en-us/library/system.componentmodel.canceleventargs.cancel%28v=vs.110%29.aspx[^].

If you needed something else, please don't blame me. Learn to ask questions accurately, clarify if you need to.

Note that the method of UI development is different, this is event-oriented approach: you don't "check status", instead, you handle events. If you are poorly familiar with events, you are not ready to do UI development, first, you need to learn events.

—SA
 
Share this answer
 
v2
Comments
Member 10279246 7-Nov-13 6:51am    
Sir, question is simple... I have add Project2 into Project1... I want to make an event... when Project2.Form1 is closing.... then Project1 tell me... it is closed... I don't want to put messagebox in Project2.Form1 on closing.... I want to define that messagebox in Project1.
Sergey Alexandrovich Kryukov 7-Nov-13 9:29am    
Project is not closing, some windows is closing. There are no "project" in runtime. I explained exactly what to do. Do "resolve" that "projects" problem, I need to know what are those projects. It's impossible to help a person who don't understand the lifetime cycle and central concepts like assemblies and processes. You did not answer my question. I'm afraid you don't understand yourself what your projects do. I don't know if they are two different processes, or one is library and another is an application, or what...
—SA
I think this is what you are looking for:
VB
' Add Project Reference to Project2
Public Class Form1 ' Project1
   Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
      Dim Prj2Form1 As New Project2.Form1
      ' subscribe to the form's FormClosed event
      AddHandler Prj2Form1.FormClosed, AddressOf Project2FormClosed
      Prj2Form1.Show()
   End Sub

   Private Sub Project2FormClosed(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosedEventArgs)
      If TypeOf sender Is Project2.Form1 Then
         Dim frm As Project2.Form1 = DirectCast(sender, Project2.Form1)
         ' unsubscribe from the form's FormClosed event
         RemoveHandler frm.FormClosed, AddressOf Project2FormClosed
         MsgBox("Project2 Form Closed")
      End If
   End Sub
End Class


Please Read: AddHandler[^] and RemoveHandler[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900