C# 如何知道选定的文件
我想构建一个软件。
该软件只会获取当前所选文件的路径。
假设我单击桌面上的一个文件。
现在我想获取这个文件的路径。
因此,每当进行新选择时,只需获取新选择文件的路径即可。
有什么想法吗?
I want to build a software.
This software will just get the path of currently selected file.
Suppose I click a file on my desktop.
Now I want to get the path of this file.
So whenever a new selection is made just get the path of newly selected file.
Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
Windows 桌面窗口最终是一个 ListView 控件(至少在 Windows XP 中是这样......),因此如果您需要知道 ListView 的选定项目,您基本上需要获取桌面的句柄并检查已选择的项目已选择。
不确定 Windows Vista 和 7 位我想这并没有太大不同,正如 David 所评论的那样,如果您希望每个资源管理器窗口都这样做可能会更困难,但仍然是可能的,请看这里作为开始:
如何获取桌面的窗口句柄?
The windows Desktop window is a ListView Control like in the end (at least it was in Windows XP...) so if you need to know selected item of a ListView you basically need to get the handle of the desktop and check what has been selected.
Not sure about windows Vista and 7 bit I guess it's not too different, as David has commented, if you want this for every single explorer window could be more difficult but should still be possible, have a look here for a start:
How do I get the window handle of the desktop?
也许您应该查看 OpenFileDialog班级
Maybe you should look at the OpenFileDialog class
我认为您可以使用肖恩所说的有关查看 OpenFileDialog 的内容。
您还可以参考下面的链接:
如何使用 OpenFileDialog
该链接还教授您如何更改标题、过滤文件类型以及有关 OpenFileDialog 的 1 或 2 个其他内容。
希望这有帮助。
I think you can use what Shaun had said about looking at OpenFileDialog.
You can also refer to this link below:
How to use OpenFileDialog
That link also teaches you how to change the title, filtering files of type and 1 or 2 others regarding OpenFileDialog.
Hope this helps.