如何在 C# 中执行 DragAcceptFiles?

发布于 2024-09-09 22:52:56 字数 355 浏览 7 评论 0原文

我正在寻找最不痛苦的方法(即用最少的代码)来实现 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

悟红尘 2024-09-16 22:52:56

您可以在表单并处理 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文