Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C# 1.0 > C#
|
C# Programming questions specific to the Microsoft C# language. See also the forum Beginning Visual C# to discuss that specific Wrox book and code.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 13th, 2003, 09:59 AM
Registered User
 
Join Date: Jun 2003
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default capturing form closed events

I'm trying to capture a form closed event, so that I can trigger a refresh of information from a database. I wrote a simple event handler to deal with it, but when I bind the actual event to the event handler, the application crashes on loading with a System.NullReference error, Object reference not set to an instance of an object.

Code:
this.updateaddr.Closed+=new System.EventHandler(this.Refres**tems);

where updateaddr is a child form, and Refres**tems is an event handler in the parent form.

I suspect that this is a problem with a really obvious solution, but I'm new to Windows programming.
 
Old June 14th, 2003, 07:59 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 453
Thanks: 0
Thanked 1 Time in 1 Post
Send a message via AIM to Ankur_Verma Send a message via MSN to Ankur_Verma
Default

I guess you missed the step of initializing your object. Or
there is a problem with the signature of your handler function.
This code is working absolutely fine for me.

Code:
    InputBox cs = new InputBox();
    cs.Closed += new System.EventHandler(this.Form1_Closed);
Make sure that the handler of the Closed event has this signature

void FormName_Closed(object sender, System.EventArgs e);

Best way to be sure about the signature of event handlers
is to add an event handler for events using wizard (if it is
available), change the name and associations of the handler
and use its body for your purpose.

Do write back if there is any thing else you wanna ask.

Ankur Verma
.Net and C++ Specialist
Wiley Tech Support
 
Old June 17th, 2003, 10:53 AM
Registered User
 
Join Date: Jun 2003
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

You were absolutely right. I hadn't initialised the instance of the form. Thanks for your help.

Alex





Similar Threads
Thread Thread Starter Forum Replies Last Post
Determining if form is closed Paula222 Access VBA 2 April 17th, 2006 02:09 AM
capturing high priority events of windows rinks Pro VB 6 0 March 16th, 2005 04:57 AM
Capturing Javascript form via Excel web query helentoomik Javascript 3 November 25th, 2004 12:19 PM
Capturing toolbar events inside a dialog class pazzuzu Visual C++ 0 October 13th, 2004 01:35 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.