Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm General / September 2004

Tip: Looking for answers? Try searching our database.

Detect Form Closing

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Derek Hart - 01 Sep 2004 17:12 GMT
I have a main form that is open by using:   Application.Run(New
fFormCriteria)

And then I have a form that runs invisible that is open by using:    Dim
myForm As New fVersionTimer

The fFormCriteria form is the form that the user will close to exit the
program.  How do I detect the Form_Closing event on frmVersionTimer?  Is it
possible?

Derek Hart
Herfried K. Wagner [MVP] - 01 Sep 2004 18:32 GMT
* "Derek Hart" <dmhart@gte.net> scripsit:
> I have a main form that is open by using:   Application.Run(New
> fFormCriteria)
[quoted text clipped - 5 lines]
> program.  How do I detect the Form_Closing event on frmVersionTimer?  Is it
> possible?

Use 'AddHandler' to add a handler to the 'fFormCriteria''s 'Closed'
event.

Signature

M S   Herfried K. Wagner
M V P  <URL:http://dotnet.mvps.org/>
V B   <URL:http://dotnet.mvps.org/dotnet/faqs/

Derek Hart - 02 Sep 2004 03:19 GMT
Why would I have to add a handler? Why doesn't the handler trigger since it
is an event in the form?

Derek Hart

>* "Derek Hart" <dmhart@gte.net> scripsit:
>> I have a main form that is open by using:   Application.Run(New
[quoted text clipped - 10 lines]
> Use 'AddHandler' to add a handler to the 'fFormCriteria''s 'Closed'
> event.
"Jeffrey Tan[MSFT]" - 02 Sep 2004 09:19 GMT
Hi Derek,

You may pass the main form's reference to the hidden form, then in the
hidden form(fVersionTimer), add the closing eventhandler for the main form.
Code like this:
   Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
       Dim f2 As New Form2(Me)
   End Sub

'In Form2, create a new constructor for passing Form1's reference
Dim p As Form1
   Public Sub New(ByVal parent As Form1)
       MyBase.New()

       Me.p = parent
       AddHandler Me.p.Closing, AddressOf ParentForm_Closing
       'This call is required by the Windows Form Designer.
       InitializeComponent()

   End Sub

   Public Sub New()
       MyBase.New()

       'This call is required by the Windows Form Designer.
       InitializeComponent()
       'Add any initialization after the InitializeComponent() call
   End Sub

 Private Sub ParentForm_Closing(ByVal sender As Object, ByVal e As
System.ComponentModel.CancelEventArgs)
       MessageBox.Show("abc")
   End Sub

=======================================
Please apply my suggestion above and let me know if it helps resolve your
problem.

Thank you for your patience and cooperation. If you have any questions or
concerns, please feel free to post it in the group. I am standing by to be
of assistance.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Signature

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

"Jeffrey Tan[MSFT]" - 08 Sep 2004 09:51 GMT
Hi Derek,

Does my reply make sense to you? Is your problem resolved? Please feel free
to tell me. Thanks

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Signature

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


Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.