tags:

views:

45

answers:

2

I need to accomplish the following.

1.) I have a winform (winformA) that is hidden instead of closed

2.) the winform in #1 is a child to the mainform, when i shutdown the mainform, the child form WinformA is disposed. I need to save data from a winform control in the winformA

The content is in a ListView in WinformA. I have tried overriding the dispose and using the destructor ~classname, but the listview items are null at that point. I cannot do it in form closing because i dont want the action to take place until the whole app is being shutdown. I cannot expose the method to the mainform due to security requirements. I have tried subscribing to Application.ApplicationExit but the event does not fire.

Any idea?

A: 

Can you save your items to a variable instead of a UI control?

Then maybe it won't be null when you reference it.

Beth
+1  A: 

I cannot do it in form closing

You have to do it from your FormClosing event handler. Pay attention to the e.CloseReason value.

Fwiw, the 'security requirements' are a pipe dream with System.Reflection in a programmer's arsenal. You'll have to setup a sandbox to prevent that.

Hans Passant