用户控件表面上的移动控件不起作用

问题描述

我建立了一个带有面板,组合框和标签用户控件。在设计时,我可以完美地移动组合框和标签,但是如果我移除面板并将组合框和标签直接放置在用户控件表面上,那么我将无法在设计时移动它们(也不能将新控件拖到用户上) -控制)。我已经包含了有效的代码。要查看它是否起作用,只需卸下面板即可。长期致力于此工作,没有任何解决方案,我们将非常感谢任何帮助。

要创建用户控件,只需简单地创建一个名为DBTest的新用户控件,在其上放置一个名为panPrimary的面板并将其设置为填充,在该面板上放置一个名为cboPrimary的组合框,并在Label上放置一个名为lblPrimary的标签。 / p>

公共类DPTest

Private Sub Setup_ParentChanged(sender As Object,e As EventArgs) Handles Me.ParentChanged

    If Me.Parent IsNot nothing Then

        Me.BorderStyle = BorderStyle.None

        TypeDescriptor.AddAttributes(Me.cboPrimary,New DesignerAttribute(GetType(DPTestItemDesigner)))
        TypeDescriptor.AddAttributes(Me.lblPrimary,New DesignerAttribute(GetType(DPTestItemDesigner)))
        TypeDescriptor.AddAttributes(Me.panPrimary,New DesignerAttribute(GetType(DPTestItemDesigner)))

    End If

End Sub

#Region“自定义设计器属性

<DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)>
Public ReadOnly Property PadLabel As LA.Core.Label
    Get
        Return Me.lblPrimary
    End Get
End Property

<DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)>
Public ReadOnly Property PadCombo As LA.Core.ComboBox
    Get
        Return Me.cboPrimary
    End Get
End Property

<DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)>
Public ReadOnly Property PadPanel As LA.Core.Panel
    Get
        Return Me.panPrimary
    End Get
End Property

#End Region

结束班级

Imports System.Drawing.Design
Public Class DPTestDesigner

    Inherits ParentControlDesigner

    Public Overrides Sub Initialize(ByVal component As IComponent)

        MyBase.Initialize(component)

        Dim DP As DPTest = CType(Me.Control,DPTest)

        Me.EnableDesignMode(DP.PadCombo,DP.PadCombo.Name)
        Me.EnableDesignMode(DP.PadLabel,DP.PadLabel.Name)
        Me.EnableDesignMode(DP.PadPanel,DP.PadPanel.Name)

    End Sub

    Public Overrides Function CanParent(ByVal control As Control) As Boolean
        Return True
    End Function

    Protected Overrides Sub OnDragOver(ByVal de As DragEventArgs)
        de.Effect = DragDropEffects.None
    End Sub


    Protected Overrides Function CreatetoolCore(ByVal tool As ToolBoxItem,ByVal x As Integer,ByVal y As Integer,ByVal width As Integer,ByVal height As Integer,ByVal hasLocation As Boolean,ByVal hasSize As Boolean) As IComponent()
        Return nothing
    End Function


End Class

Public Class DPTestItemDesigner

    Inherits ParentControlDesigner

    Public Overrides ReadOnly Property SelectionRules As SelectionRules
        Get
            Dim SRules As SelectionRules = MyBase.SelectionRules
            SRules = SRules 'And SelectionRules.auto
            Return SRules
        End Get
    End Property

    Protected Overrides Sub PostFilterattributes(ByVal attributes As IDictionary)
        MyBase.PostFilterattributes(attributes)
        attributes(GetType(DockingAttribute)) = New DockingAttribute(DockingBehavior.Never)
    End Sub


    Protected Overrides Sub PostFilterProperties(ByVal properties As IDictionary)

        MyBase.PostFilterProperties(properties)

        Dim propertiesToRemove = New String() {"AutoSize","Dock","Anchor","Size","Location","Width","Height","MinimumSize","MaximumSize","AutoSize","AutoSizeMode","Visible","Enabled"}

        For Each item In propertiesToRemove
            If properties.Contains(item) Then properties(item) = TypeDescriptor.CreateProperty(Me.Component.[GetType](),CType(properties(item),PropertyDescriptor),New browsableAttribute(False))
        Next

    End Sub
End Class

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)