Visual Studios 设计器实现中的表单继承

发布于 2024-08-30 11:25:19 字数 1072 浏览 4 评论 0原文

我正在将项目从 Visual Studio 2003 迁移到 2005,并且刚刚看到

事件 Click 是只读的,无法更改

在使用继承的表单时无法更改,无论基本表单控件上的修饰符如何都会使设计器中的所有来自基本表单的控件为只读(尽管在 2003 年,它并没有以这种方式工作)。

我发现这篇文章提到此功能已暂时“禁用” http://social. msdn.microsoft.com/Forums/en-US/winformsdesigner/thread/c25cec28-67a5-4e30-bb2d-9f8dbd41eb3a

谁能确认是否再使用此功能?或者如何围绕它进行编程以便能够使用基本控制事件并且仍然有设计器?

这是我发现的一种方法,但当它用来为你做管道工作时非常痛苦。即使只是隐藏您现在手动执行的控件之一。

Public Class BFormChild

    Friend Overrides Sub cmdApply_Click(ByVal sender As Object, ByVal e As System.EventArgs)
        MyBase.cmdApply_Click(sender, e)
    End Sub
    Friend Overrides Sub cmdCancel_Click(ByVal sender As Object, ByVal e As System.EventArgs)
        MyBase.cmdCancel_Click(sender, e)
    End Sub
    Friend Overrides Sub cmdOk_Click(ByVal sender As Object, ByVal e As System.EventArgs)
        MyBase.cmdOk_Click(sender, e)
    End Sub

End Class

I'm in the process of moving a project from Visual Studio 2003 to 2005 and have just seen the

The event Click is read-only and cannot be changed

when using inherited forms regardless of the Modifier on the Base Forms Controls will make all the Controls from the Base Readonly in the designer (Though in 2003 it didn't work this way).

I found this post mentioning that this functionality has been temporarily" disabled
http://social.msdn.microsoft.com/Forums/en-US/winformsdesigner/thread/c25cec28-67a5-4e30-bb2d-9f8dbd41eb3a

Can anyone confirm whether this feature is used anymore? Or how to program around it to be able to use the Base Control Events and still have a designer?

This is one way I've found but quite painful when it used to do the plumbing for you. Even just hiding one of the controls you have manually do now.

Public Class BFormChild

    Friend Overrides Sub cmdApply_Click(ByVal sender As Object, ByVal e As System.EventArgs)
        MyBase.cmdApply_Click(sender, e)
    End Sub
    Friend Overrides Sub cmdCancel_Click(ByVal sender As Object, ByVal e As System.EventArgs)
        MyBase.cmdCancel_Click(sender, e)
    End Sub
    Friend Overrides Sub cmdOk_Click(ByVal sender As Object, ByVal e As System.EventArgs)
        MyBase.cmdOk_Click(sender, e)
    End Sub

End Class

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

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

发布评论

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

评论(1

吃素的狼 2024-09-06 11:25:19

生成事件的基类需要标准事件生成模式。这必须在代码中完成,设计者无法自动生成它。它永远不会。

Public Class BFormBase
  Public Event ApplyClicked As EventHandler

  Protected Overridable Sub OnApplyClicked(ByVal e As EventArgs)
    '--- Possible default implementation here
    '...
    RaiseEvent ApplyClicked(Me, e)
  End Sub

  Private Sub cmdApply_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdApply.Click
    OnApplyClicked(e)
  End Sub

Base classes that generate events require the standard event generation pattern. That must be done in code, the designer cannot auto-generate it. It never will.

Public Class BFormBase
  Public Event ApplyClicked As EventHandler

  Protected Overridable Sub OnApplyClicked(ByVal e As EventArgs)
    '--- Possible default implementation here
    '...
    RaiseEvent ApplyClicked(Me, e)
  End Sub

  Private Sub cmdApply_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdApply.Click
    OnApplyClicked(e)
  End Sub
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文