The problem now is that it's showing the file size as changed when creating it. It's true that the file has changed from 0 to some size but i want it to display the creation time and the file size and then only if the file has changed again only then display the changed size in the Fsw_Changed event.
private void Fsw_Created(object sender, FileSystemEventArgs e)
{
string time = DateTime.Now.ToString("h:mm:ss tt");
if (!richTextBoxLogChanges.Text.Contains(e.FullPath))
{
AppendText(richTextBoxLogChanges, $"File Name : {e.Name} ", Color.Red);
AppendText(richTextBoxLogChanges, $"Created At : {time}", Color.Yellow);
AppendText(richTextBoxLogChanges, "\n", Color.LightGreen);
}
}
private void Fsw_Changed(object sender, FileSystemEventArgs e)
{
if (e.ChangeType != WatcherChangeTypes.Changed)
{
return;
}
else
{
var info = new FileInfo(e.FullPath);
var theSize = info.Length;
var size = SizeSuffix(theSize);
string FileN1 = "File Name : ";
string FileN2 = info.Name;
string FileN3 = " Size Changed : ";
string FileN4 = size;
if (!richTextBoxLogChanges.Text.Contains(FileN1 + FileN2 + FileN3 + FileN4))
{
AppendText(richTextBoxLogChanges, FileN1, Color.Red);
AppendText(richTextBoxLogChanges, FileN2, Color.Yellow);
AppendText(richTextBoxLogChanges, FileN3, Color.Red);
AppendText(richTextBoxLogChanges, FileN4, Color.LightBlue);
AppendText(richTextBoxLogChanges, "\n", Color.LightGreen);
}
}
}
This method generate 100 png images :
private void GenerateImages()
{
Random rand = new Random();
for (int I = 0; I < 100; I++)
{
Bitmap B = new Bitmap(rand.Next(1, 500), rand.Next(1, 500));
Graphics G = Graphics.FromImage(B);
G.DrawString(I.ToString(), this.Font, Brushes.Black, new PointF(100.0f, 100.0f));
B.Save(@"d:\Images\" + I + ".png");
B.Dispose();
}
}
private void btnGenerateFiles_Click(object sender, EventArgs e)
{
GenerateImages();
}