How to detect the close event of MMC 3.0 SnapIn written in C#

790 views Asked by At

Folks, I am creating a MMC3.0 SnapIn program with C#. There I have some scope nodes and I have FormViewDescription's where I used C# UserControl instances to display some data. And my intent is, user must see and update those data into the UserControl and there is a Save button onto that UserControl which user should press at the end of their editing and I will persist that change then.

Now the problem is, If after making some changes, user closes the SnapIn window, all his changes are gone :( I need to prevent user before closing this window with a dialog that "Save before quiting " (or something like that - you know the standard feature of any editor program). But could not found a way to do so. Any suggestions for me?

Would be appreciated much!

1

There are 1 answers

5
hydrogen On

Coincidentally, I have also just created an MMC in much the same manner as you described above but after much searching (and frustration) I could not find any way to cancel the close event. I recommend changing your approach as explained below.

First of all have a look at how most of the MMC's that are already in Windows handle changing settings. Usually if you want to change a setting you select an item in a ListView and right-click 'Properties' to bring up a settings form and make your changes there.

Bringing up a form gives the developer the ability to control the full lifecycle of the form and ensure that settings are saved before it is closed.

So my advice is:

  1. Create your FormView
  2. Add any status information you need
  3. Add a button 'Edit Settings' to your FormView
  4. Create a Windows Form with Save/Cancel + all your data input controls
  5. Launch your form with myForm.ShowDialog() when you click your 'Edit Settings' button
  6. Handle the Save/Cancel button presses and cancel appropriately if data is dirty

I hope this helps. Good luck!