a_jam_sandwich Posted February 13, 2009 Posted February 13, 2009 Hi, I�m currently creating a control inherited from the System.ComponentModel.Design.DesignSurface. So far I have been able to add & remove controls to and from the surface. Using the Selection service to find out selected controls on the surface but what I need to do now is have the ability to drag controls on this service from a very limited list of usercontrols contained within a Toolstrip and place them on the surface. The controls will need to have some properties set one places on the surface for example there is a field list that once you drag the field onto the surface the field properties are already set within that control based off what as field was initaly dragged. The only thing I need to do is figure out how to actually initate the drag and drop on a designer surface, searching the .NET had not thown up much in the was of help. Creation code for the control snippet. Public Class Designer Inherits DesignSurface Private mobjDragDrop As DesignerDragDrop Private mobjHost As Control = Nothing Private mobjSelectionService As ISelectionService = Nothing Private WithEvents mobjDesignerHost As IDesignerHost = Nothing Private Function New(ByVal RootType As Type) As IComponent ' Get the designer host/services Me.mobjDesignerHost = GetServiceDesignerHost() Me.mobjSelectionService = GetServiceSelectionService() ' Exit if the designer already exists If (mobjDesignerHost.RootComponent IsNot Nothing) Then Return mobjDesignerHost.RootComponent ' Root componant Call Me.BeginLoad(RootType) ' Get the designer host mobjDesignerHost = GetServiceDesignerHost() ' Root control Dim ctlControl As IComponent = Nothing ctlControl = mobjDesignerHost.RootComponent Return ctlControl End Function Any pointer would be greatly appreciated Thanks Andy Quote Code today gone tomorrow!
Administrators PlausiblyDamp Posted February 13, 2009 Administrators Posted February 13, 2009 Have you looked at http://www.xtremedotnettalk.com/showthread.php?t=73162 and http://www.xtremedotnettalk.com/showthread.php?t=73163 as these two postings cover designer support in quite a bit of detail and may be of some use. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
a_jam_sandwich Posted February 13, 2009 Author Posted February 13, 2009 Yes I did read Divil's articles on his website but unfortunatly it did not shine to much light. Many thanks Quote Code today gone tomorrow!
a_jam_sandwich Posted February 13, 2009 Author Posted February 13, 2009 I've created a control that implements IToolboxService and then added this control as a service to the DesignSurface, this now allow me to drag controls from my toolbox onto the designer form. Only problem now is how to set properties for the control such as the name and or text etc? Thanks Andy Quote Code today gone tomorrow!
a_jam_sandwich Posted February 14, 2009 Author Posted February 14, 2009 So much fun ... NOT Right I can drop controls onto my form using Dim objToolboxItem As New ToolboxItem(GetType(ExtendedTextbox)) Dim objToolboxService As IToolboxService = Me Dim objDataObject As DataObject = objToolboxService.SerializeToolboxItem(objToolboxItem) Call Me.DoDragDrop(objDataObject, DragDropEffects.Copy) This works fine for droping a textbox control that i've inherited from. The problem comes when I create inherited ToolboxItem which i've i'm using (hope to) to set default properties. The code i'm using below will not drag and drop on the form! <Serializable(), PermissionSetAttribute(SecurityAction.Demand, Name:="FullTrust")> _ Public Class ToolboxItemFieldBox Inherits System.Drawing.Design.ToolboxItem Public Sub New() MyBase.New() End Sub Public Sub New(ByVal ToolType As Type) MyBase.New(GetType(ExtendedTextbox)) End Sub End Class I'm at my wits end creating a designsurface to host a form editor, this has been the baine of my life this last week. Many thanks Andy Quote Code today gone tomorrow!
a_jam_sandwich Posted February 14, 2009 Author Posted February 14, 2009 In the end it was because I attempted to cast incorrectly the type on the deserialization of the toolbox item in the toolbox control. When adding a toolbox item on the designsurface the toolbox item gets serialized when calling DataObject and adding it to DoDragDrop, as you drag the item onto the designsurface this item it attempted to be deserialized in the toolbox, if it can the item is then availble for drag drop if not the deserialization returns nothing. Hope this helps anyone if they have the same problems Andy Quote Code today gone tomorrow!
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.