<分区>
在 Windows 中,无论是在桌面上还是在 Windows 资源管理器中,我想检测文件或文件夹被选中(突出显示)的时刻。发生这种情况时,我想显示一个消息框,其中显示文件或文件夹的全名。
如果选择了多个项目,我想显示所有项目。
请注意,我的解决方案必须用 C# 编写。
<分区>
在 Windows 中,无论是在桌面上还是在 Windows 资源管理器中,我想检测文件或文件夹被选中(突出显示)的时刻。发生这种情况时,我想显示一个消息框,其中显示文件或文件夹的全名。
如果选择了多个项目,我想显示所有项目。
请注意,我的解决方案必须用 C# 编写。
最佳答案
查看此示例以获取鼠标单击或选定事件:
加入以下代码,记住添加对 SHDocVW.dll 和 Shell32.dll 的引用,这将在每个资源管理器中返回所有选定的项目和文件夹路径。
public void GetListOfSelectedFilesAndFolderOfWindowsExplorer()
{
string filename;
ArrayList selected = new ArrayList();
var shell = new Shell32.Shell();
//For each explorer
foreach (SHDocVw.InternetExplorer window in new SHDocVw.ShellWindows())
{
filename = Path.GetFileNameWithoutExtension(window.FullName).ToLower();
if (filename.ToLowerInvariant() == "explorer")
{
Shell32.FolderItems items = ((Shell32.IShellFolderViewDual2)window.Document).SelectedItems();
foreach (Shell32.FolderItem item in items)
{
MessageBox.Show(item.Path.ToString());
selected.Add(item.Path);
}
}
}
}
关于c# - 在 Windows 资源管理器中检测文件选择,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13436292/