如何将图像直接从Windows资源管理器拖到我的项目 [英] How Do I Drag Images Directly From Windows Explorer To My Project

查看:108
本文介绍了如何将图像直接从Windows资源管理器拖到我的项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在项目中添加图像拖放功能。我的表单中有一个Picture box控件。我想将图像从Windows资源管理器(或任何其他应用程序)拖放到此图片框。
使用winform应用程序语言的
项目:c ++。

解决方案

您可以阅读从MSDN拖放文档 [ ^ ],在这种情况下,您处理拖动事件,然后如果拖放事件成功完成,则您处理事件以将图片的源更改为最近删除的源。



如果您转到事件(显示在文档中),您也可以获得C ++示例的源代码。只需从C#更改为C ++(或您选择的其他语言)。


您的接收窗口(放置目标)必须支持删除。使用Winforms处理 DragEnter [ ^ ]和 DragDrop [ ^ ]事件。



因为资源管理器提供文件名,所以必须检查是否通过name(s)是图像文件并从文件加载图像。对于其他来源,您可以检查是否提供了一种剪贴板图像格式(Bitmap,Dib,Tiff)或常见的用户定义图像格式(例如[image /] jpeg,[image /] gif,[image / ] PNG)。

I want to add image Drag & drop functionality in my project. I have an Picture box control in my form. I want to drag & drop images from windows explorer (or any other application) to this picture box .
project in winform application language: c++.

解决方案

You can read the Drag-and-drop document from MSDN[^], in such cases, you handle the drag events, and then if the drag-and-drop event completed successfully, then you handle the event to change the picture's source to the one that was dropped recently.

If you move to the events (shown in the document), you can get the source code for C++ samples also. Just change from C# to C++ (or other language of your choice).


Your receiving window (the drop target) must support dropping. With Winforms handle the DragEnter[^] and DragDrop[^] events.

Because the Explorer provides file names, you must check if the passed name(s) are image files and load the images from file. For other sources you may check if one of the clipboard image formats is provided (Bitmap, Dib, Tiff) or common user defined image formats (e.g. "[image/]jpeg", "[image/]gif", "[image/]png").


这篇关于如何将图像直接从Windows资源管理器拖到我的项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆