0

注意:我放置 C# 标签是为了更清楚地了解这个问题,作为对我来说很好的 C# 答案,我将能够将它翻译成 VB .NET。我面临的问题是 .NET Framework 中的概念。

我目前正在编写一个图形设计师,以便用户可以将我自己的一组自定义组件添加到设计界面中,按照他们的意愿排列它们,然后将其保存到文本文件中。

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

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时,它会显示在表面下方,如图所示:

自定义组件错误显示

这是我删除时的结果DesignAttribute

自定义组件正确显示

这是我真正想要展示的。

我的问题

为了完成这项工作,我在这里缺少什么?

4

1 回答 1

2

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

于 2016-08-09T13:38:46.687 回答