我创建了一个小型Windows窗体测试应用程序来尝试一些拖放代码.该表单由三个PictureBoxes组成.我的目的是从一个PictureBox中抓取一张图片,在拖动操作期间将其显示为自定义光标,然后将其放在另一个PictureBox目标上.
只要它们在同一个表单上,这从一个PictureBox到另一个PictureBox就可以正常工作.
如果我打开同一个应用程序的两个实例并尝试在它们之间拖放,我会收到以下神秘错误:
此远程处理代理没有通道接收器,这意味着服务器没有正在侦听的已注册服务器通道,或者此应用程序没有合适的客户端通道与服务器通信.
但是,出于某种原因,它可以拖放到Wordpad(但不是MS Word或画笔).
三个PictureBoxes将它们的事件连接起来如下:
foreach (Control pbx in this.Controls) {
if (pbx is PictureBox) {
pbx.AllowDrop = true;
pbx.MouseDown += new MouseEventHandler(pictureBox_MouseDown);
pbx.GiveFeedback += new GiveFeedbackEventHandler(pictureBox_GiveFeedback);
pbx.DragEnter += new DragEventHandler(pictureBox_DragEnter);
pbx.DragDrop += new DragEventHandler(pictureBox_DragDrop);
}
}
Run Code Online (Sandbox Code Playgroud)
然后是这样的四个事件:
void pictureBox_MouseDown(object sender, MouseEventArgs e) {
int width = (sender as PictureBox).Image.Width;
int height = (sender as PictureBox).Image.Height;
Bitmap bmp = new Bitmap(width, height);
Graphics g = Graphics.FromImage(bmp);
g.DrawImage((sender as PictureBox).Image, 0, 0, width, height);
g.Dispose();
cursorCreatedFromControlBitmap = CustomCursors.CreateFormCursor(bmp, …Run Code Online (Sandbox Code Playgroud) 我一直在尝试将 Gmail 附件从 Chrome 拖放到我的应用程序中。
可以将文件从电子邮件拖到桌面并在那里创建附件,所以我知道这一定是可能的。
我已经能够让它读取文件名,但是当我从数据对象读取 FileContents 时,我得到一个带有该文件链接的互联网快捷方式。
有人以前做过这个工作吗?目前的代码是针对 .txt 文件进行硬编码的
我的主要 DataObjectWrapper 类如下:
字符太多,无法全部发布,但主要方法是:
public object GetDataNative(string format, bool autoConvert)
{
switch (format)
{
case CFSTR_FILEDESCRIPTOR_A:
IntPtr fileGroupDescriptorAPointer = IntPtr.Zero;
try
{
//use the underlying IDataObject to get the FileGroupDescriptor as a MemoryStream
MemoryStream fileGroupDescriptorStream = (MemoryStream)this.underlyingDataObject.GetData(CFSTR_FILEDESCRIPTOR_A, autoConvert);
byte[] fileGroupDescriptorBytes = new byte[fileGroupDescriptorStream.Length];
fileGroupDescriptorStream.Read(fileGroupDescriptorBytes, 0, fileGroupDescriptorBytes.Length);
fileGroupDescriptorStream.Close();
//copy the file group descriptor into unmanaged memory
fileGroupDescriptorAPointer = Marshal.AllocHGlobal(fileGroupDescriptorBytes.Length);
Marshal.Copy(fileGroupDescriptorBytes, 0, fileGroupDescriptorAPointer, fileGroupDescriptorBytes.Length);
//marshal the unmanaged memory to to …Run Code Online (Sandbox Code Playgroud) 我想启用从基于Windows窗体的应用程序拖放到Windows资源管理器.最大的问题:文件存储在数据库中,因此我需要使用延迟数据渲染.有一篇关于codeproject.com的文章,但作者正在使用一个H_GLOBAL对象,这会导致文件大于aprox的内存问题.20 MB.我没有找到使用IStream对象的工作解决方案.我认为必须有可能实施,因为这不是一个不寻常的情况.(例如,FTP程序也需要这样的功能)
编辑:当用户删除文件时是否可以获取事件?所以我可以将它复制到temp并且资源管理器从那里获取它?也许有一个替代方法来解决我的问题......