Disable Drag & Drop at Design Time

2 posts, 0 answers
  1. Troy
    Troy avatar
    1 posts
    Member since:
    May 2011

    Posted 19 Sep 2014 Link to this post

    I might be going down the wrong path here but here is some
    background to why I am asking about disabling drag and drop at design time and
    am open to other solutions to my problem.

    I am looking to add multiple shapes to create a representation of a piece of
    equipment and while it operates have the shapes move on the screen in
    coordination with the equipment. The visual studio power pack shapes was an
    option but had a problem they had to be placed on the form in the exact order
    you wanted them you could not use bring to front or send to back. This caused a
    major problem as the equipment is complex and needs many shapes and to add each
    item in the exact sequence is un feasible.

    I noticed while doing some other work Telerik had a shape designer and this
    feature seemed like a good option to create all different shapes for my
    equipment representation. I tried to find the least complex telerik component
    such as a label or panel to apply the shape to. The problem I am having is when
    I drag shapes on top of each other the Design time Designer adds the shape to
    the other shape as if it were a control container. If I could stop them from
    acting as control containers this would be a workable solution to my problem.

    If anyone has any suggestions to this problem or a different solution I would appreciate

    My requirements.

    1. Able to design multiple different shapes and layer them on top of each other.
    The control needs to clip its region around the shape so you can see the shapes

    2. The shapes need a boarder

    3. The fill and boarder colors need to be able to change at run time

    4. The shape needs to be able to move and its visibility changed at run time

    Not required but a nice to have is a way to group the shapes together as one
    larger shape collection able to be placed on top of other shapes or collections
    maintaining the ability to see shapes underneath.

  2. Stefan
    Stefan avatar
    2906 posts

    Posted 23 Sep 2014 Link to this post

    Hi Troy,

    I am copying my answer from the ticket you have posted here as well, so the community can benefit from it:

    We do not offer shape control, however, implementing such should be be a tough task. Below you can find a sample demonstrating how to do that. The control can be dropped at design time, and it will automatically open the shape editor. Once you are done with the shape and close the window, the shape is applied to the control. A custom shape component will also be created at design time. 
    <ToolboxItem(True), DesignTimeVisible(True), Designer(GetType(ShapeControlDesigner))> _
    Public Class ShapeControl
        Inherits RadControl
        Private m_editor As New CustomShapeEditorForm()
        Public Property Editor() As CustomShapeEditorForm
                Return Me.m_editor
            End Get
                Me.m_editor = value
            End Set
        End Property
        Public Property Shape() As ElementShape
                Return Me.RootElement.Shape
            End Get
                Me.RootElement.Shape = value
            End Set
        End Property
        Public Sub New()
            Me.BackColor = Color.Black
            Me.RootElement.ApplyShapeToControl = True
        End Sub
    End Class
    Public Class ShapeControlDesigner
        Inherits RadControlDesignerLite
        Public Overrides Sub InitializeNewComponent(defaultValues As System.Collections.IDictionary)
            Dim shapeControl As ShapeControl = DirectCast(Me.RadControl, ShapeControl)
            Dim shape As ElementShape = EditShape()
            Dim cs As CustomShape = DirectCast(DesignerHost.CreateComponent(GetType(CustomShape)), CustomShape)
            cs.CopyFrom(DirectCast(shape, CustomShape))
            shapeControl.Shape = cs
        End Sub
        Public Function EditShape() As ElementShape
            Dim shapeControl As ShapeControl = DirectCast(Me.RadControl, ShapeControl)
            If shapeControl.Shape Is Nothing Then
                Return shapeControl.Editor.CreateShape()
                Return shapeControl.Editor.EditShape(DirectCast(shapeControl.Shape, CustomShape))
            End If
        End Function
        Protected Overrides Function CreateActionList() As RadControlDesignerLiteActionList
            Return New ShapeActionList(Me)
        End Function
    End Class
    Class ShapeActionList
        Inherits RadControlDesignerLiteActionList
        Public Sub New(designer As RadControlDesignerLite)
        End Sub
        Protected Overrides Sub AddHelpActions(actionItems As DesignerActionItemCollection)
            actionItems.Add(New DesignerActionMethodItem(Me, "OpenShapeEditor", "Open Shape Editor", "Common"))
        End Sub
        Public Sub OpenShapeEditor()
            Dim designer As ShapeControlDesigner = DirectCast(Me.Designer, ShapeControlDesigner)
        End Sub
    End Class
    Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
Back to Top