Zebra0.com

csharp listbox

Changes and Current File Name

In order to imitate the way notepad reminds you to save, we need to know if the list has changed since the last save. If it has changed, then we need to ask the user if they want to save when they either close the program or se3lect new or open from the menu.

We will create a Boolean variable changed. If we make any changes to the list box, we will set changed to true. When we save, we will set changed to false.

Because the file that is currently open might have been a file that was opened using openFileDialog or saved as using saveFileDialog, we also need a variable to keep track of the current file name.

public partial class Form1 : Form
{
   String currentFileName = "";
   Boolean changed = false;
   ...

End of lesson, Next lesson: ListBox Manager Part 2: Printing in C#