简体   繁体   中英

How can I change the text color in ListView when a new file has been added or deleted in FileSystemWatcher?

Is it possible to change the text color in ListView when a new file or folder has been added in FileSystemWatcher

So at the moment I have:

private void fileSystemWatcher1_Deleted(object sender, FileSystemEventArgs e)
{
    fileWatcher1.Items.Add(string.Format("File Deleted:  {0} File Name:  {1}", e.FullPath, e.Name));
}

private void fileSystemWatcher1_Renamed(object sender, RenamedEventArgs e)
{
    fileWatcher1.Items.Add(string.Format("File Renamed:  {0} File Name:  {1}", e.FullPath, e.Name));
}

private void fileSystemWatcher1_Created(object sender, RenamedEventArgs e)
{
    fileWatcher1.Items.Add(string.Format("File Created:  {0} File Name:  {1}", e.FullPath, e.Name));
}

What I would like to do is when a file has been created the color of the text should then be green and for Deleted it should be red and then if the file has been renamed it should be yellow.

Thanks

I found the solution.
It is actually quite simple:

Change

 fileWatcher1.Items.Add(string.Format("File Renamed:  {0} File Name:  {1}", e.FullPath, e.Name));

To

fileWatcher1.Items.Add(string.Format("File Renamed:  {0} File Name:  {1}", e.FullPath, e.Name)).ForeColor = Color.Blue;

Thanks

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM