- May 7, 2013
- 10,400
I've created a very simple test program, to play around and attempt to try new things to add to my main project at the moment (FileComparsion), at the moment I'm able to detect any changes made to the text box upon exit. However, the message box also appears when I've opened a file and haven't made any changes to that file.
I've read that the File Watcher component may be able to help, but how do I get the component to raise an event about the changes upon exiting the program?
Here's the code:
File Watcher Component Code (literally the same as code on MSDN):
I've read that the File Watcher component may be able to help, but how do I get the component to raise an event about the changes upon exiting the program?
Here's the code:
Code:
private void Form1_FormClosing(object sender, CancelEventArgs e)
{
richTextBox1.Tag = richTextBox1.Text;
if (richTextBox1.Text != richTextBox1.Tag)
{
if (MessageBox.Show("Do you wish to save any changes?", "Test", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes)
{
e.Cancel = true;
[...] Standard Save Dialog Box
File Watcher Component Code (literally the same as code on MSDN):
Code:
System.IO.FileSystemWatcher myWatcher = new System.IO.FileSystemWatcher();
myWatcher.Path = "C:\\";
myWatcher.Filter = "*.*";
myWatcher.IncludeSubdirectories = true;
myWatcher.EnableRaisingEvents = true;
myWatcher.NotifyFilter = System.IO.NotifyFilters.Size;