I work on an application that requires some fancy custom controls. Inheriting from the .net Control class has caused various problems and is making things harder as time goes on. I won't get into the specifics here, but I am creating my own light weight control architecture to avoid some of these problems. Things art working nicely, but I need to add drag and drop functionality into my architecture.
我在一个需要一些花哨的自定义控件的应用程序上工作。继承自.net Control类已经引起了各种问题,并且随着时间的推移使事情变得更加困难。我不会在这里详细说明,但我正在创建自己的轻量级控制架构,以避免一些这些问题。事物艺术很好,但我需要在我的架构中添加拖放功能。
All of the methods that I have come up with so far seem messy and error prone. I am mimicking the .net Control class in many ways, and have used the .net reflector to great benefit, but I am having a problem figuring out how to make my drag events fire (DragDrop, DragEnter, DragLeave).
到目前为止,我提出的所有方法看起来都很混乱且容易出错。我在很多方面都在模仿.net控件类,并且使用.net反射器非常有用,但是我在解决如何使我的拖动事件触发时遇到问题(DragDrop,DragEnter,DragLeave)。
I just can't think of a clean way to fire off these events. Does anyone have any ideas?
我只是想不出一个干净的方式来解雇这些事件。有没有人有任何想法?
So far, the best that I have come up with is to implement the IDropTarget interface and hope that my events will fire. They do not.
到目前为止,我提出的最好的方法是实现IDropTarget接口,并希望我的事件能够触发。他们不。
@tamberg: I read through that article and it is not really what I am looking for (thank you though). My problem is that I do not know how to implement the event system. For example, how do I know when a data object is being dragged over my custom control class? How can I raise these events (DragOver, DragDrop, etc)?
@tamberg:我读过那篇文章并不是我想要的(谢谢你)。我的问题是我不知道如何实现事件系统。例如,我如何知道何时在我的自定义控件类上拖动数据对象?如何引发这些事件(DragOver,DragDrop等)?
All of the controls in the example inherit from System.Windows.Forms.Control, which is what I am trying to avoid.
示例中的所有控件都继承自System.Windows.Forms.Control,这正是我要避免的。
1 个解决方案
#1
2
Just a guess:
只是一个猜测:
Windows Forms, Custom Controls Part 1: Mastering DragDrop (http://www.codeproject.com/KB/miscctrl/LANDragDrop.aspx)
Windows窗体,自定义控件第1部分:掌握DragDrop(http://www.codeproject.com/KB/miscctrl/LANDragDrop.aspx)
Regards, tamberg
#1
2
Just a guess:
只是一个猜测:
Windows Forms, Custom Controls Part 1: Mastering DragDrop (http://www.codeproject.com/KB/miscctrl/LANDragDrop.aspx)
Windows窗体,自定义控件第1部分:掌握DragDrop(http://www.codeproject.com/KB/miscctrl/LANDragDrop.aspx)
Regards, tamberg