自定义设计器更改设计图面

时间:2016-08-09 11:28:30

标签: c# .net vb.net design-surface

  

注意:我把C#标签用来提高这个问题的可见度   在C#中回答我很好,我将能够将其翻译成VB   。净。我面临的问题是.NET Framework中的概念。

我目前正在编写一个图形设计器,以便用户可以将我自己的一组自定义组件添加到设计图面中,根据需要进行排列,然后将其保存到文本文件中。

在大多数情况下,它工作正常,但我尝试使用自定义Designer来隐藏一些我不想向用户显示的属性:

Public Class MyDesigner
    Inherits ComponentDesigner

    Public Overrides Sub Initialize(component As IComponent)
        MyBase.Initialize(component)
    End Sub

    'These are the properties I will hide
    ' (real list is way longer)
    Private _hiddenPropertyList As String() = { _
        "AccessibleRole", _
        "AccessibleDescription", _
        "AccessibleName", _
        }

    Protected Overrides Sub PreFilterProperties(properties As IDictionary)
        MyBase.PreFilterProperties(properties)
        For Each PropName As String In _hiddenPropertyList
            If properties.Contains(PropName) Then
                'We hide the properties that are in the list
                properties.Remove(PropName) 
            End If
        Next
    End Sub
End Class

所以这并不复杂。要激活我的设计器,我必须在组件类定义中将其设置为属性:

<Designer(GetType(MyDesigner))>
Public Class MyLabel
    Inherits Label

    Public Sub New()
        MyBase.New()
    End Sub
End Class

所以这也不是很复杂。

问题

问题是,当在设计图面上创建新的MyLabel并且我设置了DesignerAttribute时,它会显示在曲面下方,如图所示:

Custom Component wrongly displayed

以下是删除DesignAttribute时的结果:

Custom Component correctly displayed

这就是我真正想要展示的内容。

我的问题

为了使这项工作,我在这里错过了什么?

1 个答案:

答案 0 :(得分:2)

您的标签是Control而不是Component。因此,您应该使用System.Windows.Forms.Design.ControlDesigner作为扩展Control的设计模式行为的基类。