定制属性视觉工作室2012

时间:2013-03-21 19:22:04

标签: vb.net visual-studio-2012

我正在尝试使用Visual Studio 2012在vb.net中创建自定义属性,但我在设计时和运行时设置自定义属性时遇到问题。这对Visual Studio 2010来说不是问题。这似乎是一个错误,但也许我忘了打开或关闭某些选项或者忘记了我的代码中的某些内容?

Public Class MyCustomButton
  Inherits Button

  Private m_MyBackgroundColor As Color
  Public Property MyBackgroundColor As Color
    Get
      Return m_MyBackgroundColor
    End Get
    Set(value As Color)
      value = m_MyBackgroundColor
      Me.BackColor = m_MyBackgroundColor
    End Set
  End Property
End Class

1 个答案:

答案 0 :(得分:0)

将setter改为:

Set(value As Color)
  m_MyBackgroundColor = value 'swapped value and m_MyBackgroundColor
  Me.BackColor = m_MyBackgroundColor
End Set