我有一个需要支持拖放的自定义应用程序.在我的应用程序中拖动网格时,在其 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.
提前致谢!
您可以将多种格式的数据添加到传递给 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# 从我的自定义应用拖放到记事本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!