using System;
using System.IO ;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

namespace FileSystemWatcher
{
	/// <summary>
	/// Summary description for Form1.
	/// </summary>
	public class Form1 : System.Windows.Forms.Form
	{
		private System.IO.FileSystemWatcher fileSystemWatcher1;
		private System.Windows.Forms.TextBox txtDir;
		private System.Windows.Forms.Button btnSetPath;
		private System.Windows.Forms.TextBox txtInfo;
		/// <summary>
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.Container components = null;

		public Form1()
		{
			//
			// Required for Windows Form Designer support
			//
			InitializeComponent();

			//
			// TODO: Add any constructor code after InitializeComponent call
			//
		}

		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if (components != null) 
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
			this.fileSystemWatcher1 = new System.IO.FileSystemWatcher();
			this.txtDir = new System.Windows.Forms.TextBox();
			this.btnSetPath = new System.Windows.Forms.Button();
			this.txtInfo = new System.Windows.Forms.TextBox();
			((System.ComponentModel.ISupportInitialize)(this.fileSystemWatcher1)).BeginInit();
			this.SuspendLayout();
			// 
			// fileSystemWatcher1
			// 
			this.fileSystemWatcher1.EnableRaisingEvents = true;
			this.fileSystemWatcher1.SynchronizingObject = this;
			this.fileSystemWatcher1.Changed += new System.IO.FileSystemEventHandler(this.fileSystemWatcher1_Changed);
			this.fileSystemWatcher1.Created += new System.IO.FileSystemEventHandler(this.fileSystemWatcher1_Created);
			this.fileSystemWatcher1.Renamed += new System.IO.RenamedEventHandler(this.fileSystemWatcher1_Renamed);
			this.fileSystemWatcher1.Deleted += new System.IO.FileSystemEventHandler(this.fileSystemWatcher1_Deleted);
			// 
			// txtDir
			// 
			this.txtDir.Location = new System.Drawing.Point(40, 24);
			this.txtDir.Name = "txtDir";
			this.txtDir.Size = new System.Drawing.Size(208, 21);
			this.txtDir.TabIndex = 0;
			this.txtDir.Text = "";
			// 
			// btnSetPath
			// 
			this.btnSetPath.Location = new System.Drawing.Point(112, 64);
			this.btnSetPath.Name = "btnSetPath";
			this.btnSetPath.TabIndex = 1;
			this.btnSetPath.Text = "设置路径";
			this.btnSetPath.Click += new System.EventHandler(this.btnSetPath_Click);
			// 
			// txtInfo
			// 
			this.txtInfo.Location = new System.Drawing.Point(40, 104);
			this.txtInfo.Multiline = true;
			this.txtInfo.Name = "txtInfo";
			this.txtInfo.ScrollBars = System.Windows.Forms.ScrollBars.Vertical;
			this.txtInfo.Size = new System.Drawing.Size(208, 176);
			this.txtInfo.TabIndex = 2;
			this.txtInfo.Text = "";
			// 
			// Form1
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
			this.ClientSize = new System.Drawing.Size(292, 293);
			this.Controls.AddRange(new System.Windows.Forms.Control[] {
																		  this.txtInfo,
																		  this.btnSetPath,
																		  this.txtDir});
			this.Name = "Form1";
			this.Text = "文件系统监视器";
			
			((System.ComponentModel.ISupportInitialize)(this.fileSystemWatcher1)).EndInit();
			this.ResumeLayout(false);

		}
		#endregion

		/// <summary>
		/// The main entry point for the application.
		/// </summary>
		[STAThread]
		static void Main() 
		{
			Application.Run(new Form1());
		}

		private void btnSetPath_Click(object sender, System.EventArgs e)
		{
			fileSystemWatcher1.Path=txtDir.Text;
		}

		private void fileSystemWatcher1_Changed(object sender, System.IO.FileSystemEventArgs e)
		{
			txtInfo.Text += "ChangeType :: " + e.ChangeType.ToString() + "\nFullPath ::" + e.FullPath.ToString() + "\n\n";

		}

		protected void fileSystemWatcher1_Created(object sender, FileSystemEventArgs e)
		{ 
			txtInfo.Text += "ChangeType :: " + e.ChangeType.ToString() + "\nFullPath ::" + e.FullPath.ToString() + "\n\n";
		} 
		
 
						  
 
		 protected void fileSystemWatcher1_Deleted(object sender, FileSystemEventArgs e)
		{ 
			  txtInfo.Text += "ChangeType :: " + e.ChangeType.ToString() + "\nFullPath ::" + e.FullPath.ToString() + "\n\n";
		} 


		protected void fileSystemWatcher1_Renamed(object sender, RenamedEventArgs e)
		{
				txtInfo.Text += "ChangeType :: " + e.ChangeType.ToString() + "\nFullPath ::" + e.FullPath.ToString() + "\nOld FileName :: "+ e.OldName.ToString() + "\n\n";
		}

	}
}
