using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; namespace WindowsFormsApplication1 { public partial class Form1 : Form { int i = 0; int flag = 0; public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { FilesWacher.FWacher(this); } private void timer1_Tick(object sender, EventArgs e) { if (flag == 0) { string Caption = "Песочница by JusteG™ "; this.Text = Caption.Substring(0, i); i++; if (i == Caption.Length) flag = 1; } else { string Caption = "Песочница by JusteG™ "; this.Text = Caption.Substring(0, i); i--; if (i == 0) flag = 0; } } private void button1_Click(object sender, EventArgs e) { if (richTextBox1.ForeColor.ToString() == System.Drawing.Color.Black.ToString()) richTextBox1.ForeColor = System.Drawing.Color.Red; else richTextBox1.ForeColor = System.Drawing.Color.Black; } private void button2_Click(object sender, EventArgs e) { string TextFromEdit = richTextBox1.Text.ToString(); TextFromEdit = TextFromEdit + " \n \n JusteG™ \n"; richTextBox1.Text = TextFromEdit; } private void richTextBox1_TextChanged(object sender, EventArgs e) { } private void button3_Click(object sender, EventArgs e) { string TextFromEdit = richTextBox1.Text.ToString(); double Num = Convert.ToDouble(TextFromEdit); richTextBox1.Text = (Num * 2).ToString(); } private void button4_Click(object sender, EventArgs e) { try { string[] dirs = System.IO.Directory.GetDirectories(@"C:\"); richTextBox1.Text = "Всего дирректорий на диске С: - " + dirs.Length.ToString() + "\n Список: \n"; foreach (string dir in dirs) { richTextBox1.Text = richTextBox1.Text + "\n" + dir; } } catch (Exception) { richTextBox1.Text = richTextBox1.Text + "\n" + "False"; } } private void button5_Click(object sender, EventArgs e) { if (button4.ForeColor == System.Drawing.Color.Red) button4.ForeColor = System.Drawing.Color.Black; else button4.ForeColor = System.Drawing.Color.Red; } public void SetText(string EditText) { richTextBox1.Text += EditText; } } public class FilesWacher { private static Form1 parent; public static void FWacher(Form1 parent) { FilesWacher.parent = parent; System.IO.FileSystemWatcher Watcher = new System.IO.FileSystemWatcher(); Watcher.Path = @"C:\"; Watcher.NotifyFilter = System.IO.NotifyFilters.LastAccess | System.IO.NotifyFilters.LastWrite | System.IO.NotifyFilters.FileName | System.IO.NotifyFilters.DirectoryName; Watcher.Filter = "*.txt"; Watcher.Changed += new System.IO.FileSystemEventHandler(OnChanged); Watcher.Created += new System.IO.FileSystemEventHandler(OnCreated); Watcher.Deleted += new System.IO.FileSystemEventHandler(OnDeleted); Watcher.Renamed += new System.IO.RenamedEventHandler(OnRenamed); Watcher.EnableRaisingEvents = true; System.IO.StreamWriter sw; sw = System.IO.File.AppendText(@"C:\Test.txt"); sw.WriteLine("Запущен процесс слежения за файлами"); sw.Close(); parent.SetText("Запущен процесс слежения за файлами"); } private static void OnChanged(object sourse, System.IO.FileSystemEventArgs e) { parent.Invoke(new MethodInvoker(delegate() { parent.SetText("Файл: " + e.FullPath + " был изменен"); })); } private static void OnCreated(object sourse, System.IO.FileSystemEventArgs e) { parent.Invoke(new MethodInvoker(delegate() { parent.SetText("Файл: " + e.FullPath + " был создан"); })); } private static void OnDeleted(object sourse, System.IO.FileSystemEventArgs e) { parent.Invoke(new MethodInvoker(delegate() { parent.SetText("Файл: " + e.FullPath + " был удален"); })); } private static void OnRenamed(object sourse, System.IO.FileSystemEventArgs e) { parent.Invoke(new MethodInvoker(delegate() { parent.SetText("Файл: " + e.FullPath + " был переименован"); })); } } } |