如何在 C# 中执行 DragAcceptFiles?
我正在寻找最不痛苦的方法(即用最少的代码)来实现 DragAcceptFiles 。
我一直在网上搜索,看起来我必须 DllImport DragAcceptFiles 并重写 WndProc 来捕获和处理 WM_DROPFILES 消息。
.net-framework 没有在某个地方提供这个吗? 除了重写 WndProc 之外,是否没有正确的方法将消息处理程序添加到表单中,并让它对几乎所有其他消息执行额外的 if 操作?
I'm looking for the least painful way (that is, with the least code) to implement DragAcceptFiles on the main window of a C# project.
I've been searching on the net, and it looks like I'll have to DllImport DragAcceptFiles, and override WndProc to catch and handle WM_DROPFILES messages.
Doesn't the .net-framework provide this somewhere?
Isn't there a proper way to add message handlers to a form other than overriding WndProc and have it do an extra if on almost all other messages that come through?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以在表单并处理 DragDrop 事件。查看 DragEventArgs 类用于加载拖放到控件上的文件的代码。
You can enable AllowDrop on the form and handle the DragDrop event. Take a look at the DragEventArgs class for the code for loading a file dropped onto a control.