开发者

Form Inheritance in Visual Studios designer implementations

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 fo开发者_C百科rms 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


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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜