1

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!

Moim
  • 486
  • 1
  • 8
  • 23

1 Answers1

1

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!

hydrogen
  • 2,878
  • 21
  • 20
  • Hi Thanks a lot for your reply. I know what you meant, and in fact, I also thought about a pop-up dialog based edit scenarios. But for my case, it's probably not possible because of the following reasons: 1. I have many nodes with their details pages. So it's would take a big amount of time to create popup edit page for each of them, also a read only page for general display. 2. Beside the double development efforts, my clients do not like pop-up dialogs to configure each nodes out there. I can imagine, the frustration you had already, but good news for me is I finally resolved my problem. – Moim Aug 17 '10 at 06:39
  • How I resolved my problem : I used an Native window interceptor to intercept the WindProc method for the parent SnapIn and only the child nodes that I am working with. Intercepting the WM_Close message, my solution just looks awesome. Just like a wordpad instance, it prompts before closing with yes, no, cancel and does what it needs to do, based on the user selection. Happy programming and thanks again! – Moim Aug 17 '10 at 06:41
  • Awesome! I guess you used this class: http://msdn.microsoft.com/en-us/library/system.windows.forms.nativewindow.wndproc.aspx I don't know why I never found that during my search! If you get time, try and post a code sample as i'm sure someone else will one day benefit from this as well. – hydrogen Aug 17 '10 at 08:53
  • I have written a blog post with the code sample, so that anyone facing this same issue can find a work around. BTW, thanks for your time to answer this thread. Happy programming! – Moim Aug 17 '10 at 15:13
  • 1
    Here is the link : http://moimtechview.blogspot.com/2010/08/prompt-for-save-changes-in-mmc-30.html – Moim Aug 17 '10 at 15:13