在 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);
}
}
}
}
只需在 Renier 的回答中添加一些内容: