具有列表类型属性的用户控件未更新

时间:2018-12-08 02:58:00

标签: vb.net winforms user-controls

我编写了一个VB.NET用户控件,该控件继承自应该包含许多按钮的面板。我的实现将按钮存储为List(of Button)。裸露的代码显示在下面。当我在设计时编辑控件时,集合编辑器会正确打开,按钮也可以正确添加,但是在设计时或运行时它们都不会出现在控件中。表单设计器文件显示它们没有添加到面板的Controls集合中。我在做什么错了?

Imports System.ComponentModel
Imports System.Collections

Public Class ePanel
     Inherits Panel

Private ButtonList As List(Of Button)


<DesignerSerializationVisibility(DesignerSerializationVisibility.Content), Description("Button list")>
Public Property Buttons As List(Of Button)
    Get
        Return (ButtonList)
    End Get
    Set(ByVal value As List(Of Button))
        ButtonList.Clear()
        ButtonList = value
        If (ButtonList.Count > 0) Then
            For Each b As Button In ButtonList
                Me.Controls.Add(b)
            Next
        End If
    End Set
End Property



Public Sub New()

    MyBase.BorderStyle = BorderStyle.FixedSingle
    MyBase.BackColor = Color.Bisque

    If (ButtonList.Count > 0) Then
        For Each b As Button In ButtonList
            b.Dock = DockStyle.Top
            Me.Controls.Add(b)
        Next
    End If

End Sub 
End Class

0 个答案:

没有答案