继承的属性在设计器中不可编辑

发布于 2024-10-09 08:01:50 字数 1450 浏览 4 评论 0 原文

我有一个基表单类,它提供一个看起来像这样的新属性。

Public Class BaseForm

    Private _HappyTime As Boolean

    Public Property HappyTime() As Boolean
        Get
            Return _HappyTime
        End Get
        Set(ByVal value As Boolean)
            _HappyTime = Value
        End Set
    End Property

End Class

<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Partial Class BaseForm
    Inherits System.Windows.Forms.Form

    <System.Diagnostics.DebuggerNonUserCode()> _
    Protected Overrides Sub Dispose(ByVal disposing As Boolean)
        Try
            If disposing AndAlso components IsNot Nothing Then
                components.Dispose()
            End If
        Finally
            MyBase.Dispose(disposing)
        End Try
    End Sub

    Private components As System.ComponentModel.IContainer

    <System.Diagnostics.DebuggerStepThrough()> _
    Private Sub InitializeComponent()
        components = New System.ComponentModel.Container
        Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
        Me.Text = "BaseForm"
    End Sub
End Class

现在,当我在新表单上继承 BaseForm 时,HappyTime 属性在属性窗口中显示为 false,并且不可编辑。

我在一个全新的解决方案中重新创建了这个 BaseForm 和 Inheriting Form,并且 HappyTime 属性是可编辑的并且按预期工作。由于某些原因,在现有项目(需要进行这些更改)中,它的行为不正常。

这让我相信这与我的项目配置有关。除了创建一个新项目并将所有代码移入其中之外,有人对此有任何见解吗?

环境信息: .Net Framework 3.5、Visual Studio 2010、Win7 x64

I have a base form class that is providing a new property that looks Like this

Public Class BaseForm

    Private _HappyTime As Boolean

    Public Property HappyTime() As Boolean
        Get
            Return _HappyTime
        End Get
        Set(ByVal value As Boolean)
            _HappyTime = Value
        End Set
    End Property

End Class

<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Partial Class BaseForm
    Inherits System.Windows.Forms.Form

    <System.Diagnostics.DebuggerNonUserCode()> _
    Protected Overrides Sub Dispose(ByVal disposing As Boolean)
        Try
            If disposing AndAlso components IsNot Nothing Then
                components.Dispose()
            End If
        Finally
            MyBase.Dispose(disposing)
        End Try
    End Sub

    Private components As System.ComponentModel.IContainer

    <System.Diagnostics.DebuggerStepThrough()> _
    Private Sub InitializeComponent()
        components = New System.ComponentModel.Container
        Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
        Me.Text = "BaseForm"
    End Sub
End Class

Now when I inherit the BaseForm on a new form, the HappyTime property displays in the properties window as false, and is uneditable.

I've recreated this BaseForm and Inheriting Form in an entirely new soloution and, the HappyTime property is editable and works as expected. For some reason in the existing project (where these changes need to be made) it's not behaving properly.

This leads me to believe that it has something to do with the configuration of my project. Does anybody have any insight into this, short of creating a new project and moving all the code into it?

Environment Information:
.Net Framework 3.5, Visual Studio 2010, Win7 x64

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

心房的律动 2024-10-16 08:01:50

在重新创建的解决方案中,_HappyTime 属性是私有还是受保护?我认为,如果您在此解决方案中将其更改为“受保护”,它就会起作用。

In the recreated solution, is the _HappyTime property Private or Protected? I think that if you just change it to Protected in this solution, it'll work.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文