Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Subclass and Reuse
Message
From
17/11/2004 12:48:52
 
General information
Forum:
ASP.NET
Category:
Other
Environment versions
Environment:
VB.NET 1.1
OS:
Windows XP SP1
Database:
MS SQL Server
Miscellaneous
Thread ID:
00961677
Message ID:
00962287
Views:
8
Bernard,

I was thinking more along the lines of this:
Public Class SubClassedForm
    Inherits BaseClasses.BaseForm

    Public Sub MyPreClickCode(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BaseCommandButton1.PreClick
        MsgBox("Preclick")
        ' Subsequent code determines that we don't want to do the default
        ' First cast the sender object to your Button base class and call it MyButton
        ' I don't know the syntax of this in VB, but I'm sure you do <g>
        MyButton.DoDefault = false
    End Sub

    Public Sub MyPostClickCode(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BaseCommandButton1.PostClick
        MsgBox("PostClick")
    End Sub

End Class
Then in your Button base class, add the property and check it before doing the default
Public Class BaseCommandButton
    Inherits System.Windows.Forms.UserControl

    ' Whatever the VB syntax is for a public property:
    Public bool DoDefault = true

    Public Event PreClick As EventHandler
    Public Event PostClick As EventHandler

    Private Sub BaseButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BaseButton.Click
        RaiseEvent PreClick(sender, e)

        '------------------default code goes here---------------------
        If DoDefault Then
            MsgBox("parent click at class level")
        End If
        '------------------default code goes here---------------------

        RaiseEvent PostClick(sender, e)
    End Sub
End Class
~~Bonnie


>Hi Bonnie,
>
>Thanks for that again....
>
>adding a boolean in order to bypass the default code would work great....
>
>Taking this to the next level, how would you override the default code at an instance level.?
>
>something like this :-
>
>instance.preclick fires and we determine that we don't want to run the default code, but do something else instead..something along the lines of this pseudo code..
>
>if instance.preclick
> do the defaultcode in the parent class
>else
> do something else
>endif
>instance.postclick
>
>hope you can help me out with this, it's not my intention to keep bothering you ..
>
>All the best, bernard
Bonnie Berent DeWitt
NET/C# MVP since 2003

http://geek-goddess-bonnie.blogspot.com
Previous
Reply
Map
View

Click here to load this message in the networking platform