c# 从我的自定义应用拖放到记事本

c# Drag and Drop from my custom app to notepad(c# 从我的自定义应用拖放到记事本)
本文介绍了c# 从我的自定义应用拖放到记事本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

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

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.

我想要做的是让源应用程序也能够放入 NotePad/TextPad.我可以看到我可以将文件从 Windows 资源管理器拖放到记事本,但无法将纯文本拖放到记事本.猜猜它会检查 DragEnter 事件中的 DataFormat 并禁止字符串,但允许将文件放入其中.

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.

  • 有没有办法在源应用程序中更改 yr 格式,以便它提供临时文件/字符串.
  • 是否可以提供 2 种格式的数据,以便目标 drop 可以接受它喜欢的任何格式?

提前致谢!

推荐答案

您可以将多种格式的数据添加到传递给 DoDragDrop 调用的 DataObject 中,因此只需添加另一个对 SetData 的调用以添加新格式.这是最合适的实现,这样 Drop 目标可以查询可用格式并选择它最喜欢的格式.

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# 从我的自定义应用拖放到记事本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

Multicast delegate weird behavior in C#?(C# 中的多播委托奇怪行为?)
Parameter count mismatch with Invoke?(参数计数与调用不匹配?)
How to store delegates in a List(如何将代表存储在列表中)
How delegates work (in the background)?(代表如何工作(在后台)?)
C# Asynchronous call without EndInvoke?(没有 EndInvoke 的 C# 异步调用?)
Delegate.CreateDelegate() and generics: Error binding to target method(Delegate.CreateDelegate() 和泛型:错误绑定到目标方法)