简体   繁体   English

在 FileSystemWatcher 中添加或删除新文件时,如何更改 ListView 中的文本颜色?

[英]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 FileSystemWatcherFileSystemWatcher添加新文件或文件夹时,是否可以更改ListView的文本颜色

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谢谢

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何更改 listView ColumnHeader 文本颜色? - How can i change listView ColumnHeader text color? FTP 的 FileSystemWatcher 在将新文件添加到文件夹时不通知 - FileSystemWatcher for FTP not notifying when a new file is added to folder 将新文件添加到 Google 云端硬盘时,FileSystemWatcher 不会收到通知 - FileSystemWatcher does not get notified when a new file is added to Google Drive 我如何知道何时删除了 Azure 文件存储共享? - How do I know when an Azure File Storage share has been deleted? 如何使用FileSystemWatcher查看目录并仍然允许正确删除它? - How can I watch a directory with a FileSystemWatcher and still allow for it to be properly deleted? 我如何使用 FileSystemWatcher 创建而不改变 - How can i use FileSystemWatcher created not change IsFocused属性不适用于WPF中的ListView吗? 当我按Tab或单击ListView时,如何更改ListView的边框颜色? - The IsFocused property does not work for ListView in WPF? How can i change the border color of ListView when i press tab or click on the ListView? 轻按其各自的父级(列表视图的项目)后,如何更改标签的文本颜色? - How can I change the text color of a label after its respective parent(item of a listview) is tapped? 如何在动态列表框中实现“添加新项”文本并更改其在添加项上的位置? - How can I implement “add new item” text in dynamic listbox and change its position on item added? 如何更改按钮文本的颜色? - How can I change the color of the text of a button?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM