VB.NET - form closing code is not right - Asked By jenn on 22-May-10 01:59 PM

hi guys :)

I am still working on this notepad and I am now having trouble with my closing. The closing code is not picking up the fact that the save button was used. In otherwords...I can save my changes, and then hit the X to close the form and the dialog will ask me if I want to exit without saving changes.

not sure what I need to do here at all to fix this. I just know it is not complete...

Phivos Stylianides replied to jenn on 22-May-10 02:15 PM

Your method is correct. It won't magically know that you hit the save button! Here is what you can do. Keep a boolean variable in your class called isChanged. Whenever the user makes any changes to the text set it to true and whenever the user clicks save set it to false. Then in your FormClosing method check if that value is true and only then display the dialog box, otherwise continue with closing the form.

I am being told that Close Reason is not a member, Else must have matching ElseIf, end must have matching endIf, a a end of expression is expected..

Phivos Stylianides replied to jenn on 22-May-10 03:48 PM

Morning Jenn!

The method you pasted here, when the form closes it directly displays the dialog box without checking any condition first. So if you want to check that flag and then if true show the dialog it should be something like this:

thank you for your post I did try this method but when I click no..the dialog box stays and will only disappear when I click yes..this quite possibly could be an error on my part, but I did go with Phivos on his recommendations and have it working perfectly now :)

Super Man replied to jenn on 24-May-10 12:47 AM

I assumed that you have taken RichTextBox.

there is one Property Modified, you can make use of it, and you can also set its value.

whenever you right in RichTextBox. Modified property returns true. so whenever user formclose then use