c#从我的自定义应用程序拖放到记事本 [英] c# Drag and Drop from my custom app to notepad

查看:93
本文介绍了c#从我的自定义应用程序拖放到记事本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个需要支持拖放的自定义应用程序。
在我的应用程序中拖动网格,在其DoDragDrop方法中,我提供了要以序列化格式删除的对象。



当下降到一个我的应用程序,它可以无条件的字符串和创建对象。



我想做的是允许源应用程序能够放入笔记本电脑/以及。我可以看到我可以将文件从Windows资源管理器拖放到记事本,但是不能将纯文本拖放到笔记本电脑。猜测它会检查DragEnter事件中的DataFormat,并禁止使用字符串,但允许将文件放入其中。




  • 有没有办法更改源代码应用程序中的yr格式,以便它提供一个临时文件/一个字符串。

  • 是否可以提供2种格式的数据,以便目标下载可以接受任何格式快乐吗?



提前感谢

解决方案

您可以将多种格式的数据添加到您传入DoDragDrop调用的DataObject中,因此只需添加另一个调用SetData即可添加新格式。这是最合适的实现方式,这种Drop目标可以查询可用的格式,并选择最适合的格式。

  DataObject d = new DataObject(); 
d.SetData(DataFormats.Serializable,myObject);
d.SetData(DataFormats.Text,myObject.ToString());
myForm.DoDragDrop(d,DragDropEffects.Copy);


I have a custom app which needs to support Drag and Drop. On Dragging the grid in my app, in its DoDragDrop method I have provided the object to be dropped in a serialized format.

When the drop is to one of my apps, it is able to deserailize the string and create the object.

What I want to do is allow the source app to be able to drop into NotePad/TextPad as well. I can see that I can drag and drop files from windows explorer to Notepad , but am not able to drag and drop plain text to NotePad. Guess it checks the DataFormat in the DragEnter event and dis-allows strings but allows files to be dropped into it.

  • Is there a way to change yr format in the source app so that it provides a temp file / a string.
  • Is it possible to provide the data in 2 formats so that the target drop can accept whichever format it is happy with?

thanks in advance!

解决方案

You can add multiple formats of your data to the DataObject you pass into the DoDragDrop call, so just add another call to SetData to add the new formats. This is the most appropriate implementation, this way the Drop target can query for available formats and choose the one it likes best.

 DataObject d = new DataObject();
 d.SetData(DataFormats.Serializable, myObject);
 d.SetData(DataFormats.Text, myObject.ToString());
 myForm.DoDragDrop(d, DragDropEffects.Copy);

这篇关于c#从我的自定义应用程序拖放到记事本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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