设计时拖放
我目前正在开发一个项目,我的部分是设计一个设计界面,最终用户可以在运行时添加/删除/移动控件。
我遵循了本教程 “托管 Windows 窗体设计器,作者:Tim Dawson”,几乎已经实现了我需要的所有功能。
为那些不想阅读教程的人提供的简短故事:我实现了IDesignerHost
, IContainer
,ISelectionService
,IToolboxService
和其他一些接口,用于创建我的设计界面。我没有使用 System.ComponentModel.Design.DesignSurface
已经在框架中,主要是因为我需要一个真正自定义的设计界面。
问题:
我想允许用户拖动&将新的Control
从IToolboxService
拖放到IDesignerHost/IContainer
。在本教程中,您将单击工具箱中的Control
,然后单击设计图面以添加该控件。
我发现:
- 有一个内置功能 自动进行拖拽操作掉落自
IToolboxService
到System.ComponentModel.Design.DesignSurface
但如果您从无到有实现 IDesignerHost,它显然不起作用。 当您使用
Control.DoDragDrop(ToolboxItem)
方法,启动拖放掉落:IToolboxService.SerializeToolboxItem(ToolboxItem)
被调用来序列化该项目IToolboxService.IsToolboxItem(对象)
和IToolboxService.IsSupported(对象)
被调用来评估是否
可以允许序列化 ToolboxItem 放置在设计表面上- 当您放下控件时:设计界面会调用
IToolboxService.DeserializeToolboxItem(object serializedObject)
来反序列化所放下的控件。
IToolboxService.SetCursor()
被调用以了解您是否定义自定义光标,还是让标准 Windows 光标。
问题:
我在“我发现的内容”中实现了上面提到的所有内容,但是拖动& drop is buggy :
- 我拖动,一切都很好,但是当 悬停在设计表面上,我的 光标在之间稍微闪烁 标准光标和 “
DragDropEffects.Copy
”样式。 - 当我放下时,什么也没有发生,当我的光标离开设计表面时(放下后),就会创建新的
Control
并将其添加到我放下它的位置。
有没有人尝试过做我正在做的事情,如果是的话,你是如何做到的? 有人有任何指针/链接/好的建议吗?
谢谢=)
I'm currently working of a project where my part is to design a Design Surface where the end user can add/remove/move controls at run-time.
I followed this tutorial "Hosting Windows Forms Designers, by Tim Dawson", and almost have implemented all the features I need.
Short story for those who don't want to read the tutorial : I implemented IDesignerHost
, IContainer
, ISelectionService
, IToolboxService
and some other interface, to create my design surface. I didn't use the System.ComponentModel.Design.DesignSurface
already in the framework, mainly beacause I need a really custom design surface.
Question :
I want to allow user to drag & drop new Control
from the IToolboxService
to the IDesignerHost/IContainer
. In this tutorial, you clic on a Control
in the toolbox, the click on the design surface to add the control.
What i've found :
- There is a built-in feature that
automagically does drag & drop fromIToolboxService
toSystem.ComponentModel.Design.DesignSurface
but it is clearly not working if you implement IDesignerHost from nothing. When you use the
Control.DoDragDrop(ToolboxItem)
method, to initiate a drag & drop :IToolboxService.SerializeToolboxItem(ToolboxItem)
is called to serialize the itemIToolboxService.IsToolboxItem(object)
andIToolboxService.IsSupported(object)
are called to evaluate if the
serialized ToolboxItem can be allowed
to be droped on the design surface- When you drop the control :
IToolboxService.DeserializeToolboxItem(object serializedObject)
is called by the design surface to deserialize the controldropped.
IToolboxService.SetCursor()
is called to know if you define a custom cursor, or let the standard windows cursor.
Problem :
I implemented all mentionned above, in the "What i've found", but the drag & drop is buggy :
- I drag, everything's fine, but when
hovering the design surface, my
cursor blink a little between
standard cursor and the
"DragDropEffects.Copy
" style. - When I drop, nothing happens, and when my cursor leave the design surface (after I dropped), then the new
Control
is created and added where I dropped it.
Has anyone ever tried to do what I'm doing, and if so, how did you manage it ?
Is there anyone that has any pointer/link/good advices ?
Thank you =)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您的问题似乎已通过 Microsoft Connect 问题 消耗/未消耗的鼠标事件得到解决由 2.0 设计师培养。虽然这个问题很容易理解,但显然从 .NET Framework 1.1 (2003) 到 2.0 (2006) 的升级意味着拖拽和渲染方面的变化。删除行为 - 鉴于您提到的文章源于 2003 年,这很可能是相关的。具体来说,您应该向前滚动到第 问题 2 部分,引用:
我现在无法自己深入研究这个问题,但您也可以从 自定义拖放放入设计器,它解决了有关拖动和拖动的行为变化。 Visual Studio 版本 2003 和 2005 之间下降;这很可能是相关的,并且已接受的答案之一实际上具体引用了上面的 Microsoft Connect 问题,而且它还提供了更多可能解决方案的提示。
Your issue seems to be addressed by the Microsoft Connect issue Mouse Events Consumed / Not Raised in 2.0 Designers. This issue is all but easy to grasp though, but apparently the upgrade from .NET Framework 1.1 (2003) to 2.0 (2006) implied a change in drag & drop behavior - given that the article you mentioned stems from 2003 this could well be related. Specifically you should scroll ahead to section Issue 2, citation:
I'm unable to dig deeper into this right now myself but you might also be able to figure something from Customize Drag & Drop in the Designer, which addresses changed behavior regarding drag & drop between Visual Studio versions 2003 and 2005; quite likely this might be related and one of the accepted answers does in fact specifically reference the Microsoft Connect issue above, plus it offers more hints towards possible solutions too.
我一天前就解决了这个问题。这是我为我的项目(如您的项目)找到的解决方案。
这是我的工具箱服务。
有“DesignPanel”属性和“SetCursor”方法。 DesignPanel 属性是根设计器视图的控件。
EasyAccordionToolBoxService 中有一个从 IToolboxService 实现的 GetSelectedToolboxItem 方法。 GetSelectedToolboxItem 就是您的答案。
最后,
Me to worked on this questions for one day ago. This is my solution that found for my project like yours.
This is my toolboxservice.
There are "DesignPanel" property and "SetCursor" methods. DesignPanel property is control referred to view of root designer.
There is GetSelectedToolboxItem method in EasyAccordionToolBoxService implemented from IToolboxService. GetSelectedToolboxItem is your answer.
Finally,