Subclassing a PagePanel to add fade effects

I was looking at the MBSOverlay examples and got distracted by Christian’s FadingInterfaceFx class. It’s a cool little cross-platform class that allows you to easily add a fade effect to a portion of the screen (e.g. when changing pages of a PagePanel among other things).

I’ve added the class to my project and it works well, but I got to thinking that the correct way to do this would be to subclass the PagePanel and add a “UseFadeEffet” property. I’ve never subclassed a built in control before and have a few questions. Here’s what I’ve done:

Created clsPagePanel who’s Super is PagePanel

I’ve added the following to my subclass:

UseFadeEfect As Boolean

Property Value As Integer

Get
  Return Super.Value
End Get

Set
  If value <> Super.Value Then 
    If UseFadeEfect Then
      Dim o As FadingInterfaceFx
      o = New FadingInterfaceFx(Self.Left + Me.Left, Self.Top + Me.Top, Me.Width, Me.Height , True)
      o.MakeScreenshot
      Super.Value = value
      o.Show
    Else
      Super.Value = value
    End If
  End If
End Set

Unfortunately everywhere I reference “Super.Value” it says that item doesn’t exist. I haven’t had any luck finding information on how to go about this in the documentation, and the example code folder doesn’t seem to have any index or explanation at all. Can someone point out the obvious in what I’ve done wrong.

Cheers.

-bill k

Value is a property of your subclass, not it’s super, so you use just Value. But the setters parameter is named value so this will be confusing in that code.

Instead I’d rename Value to something more descriptive like fadeEffectValue and just reference it as that.

Overloading (and the Super keyword) only works with methods, but PagePanel.Value is a property. What you’re doing is called “shadowing” the property, and it’s not recommended as it can lead to hard to diagnose problems an unexpected behavior. If you insist on doing it, you have to upcast the instance, e.g. : PagePanel(Me).Value = 0 not Super.Value = 0.

I would suggest using a different name for your subclass property.

A slightly better alternative to shadowing is to create getter and setter methods named “Value”:

Function Value() As Integer
    Return PagePanel(Me).Value  ' this is only marginally better than shadowing
End Function


Sub Value(Assigns NewValue Integer)
    PagePanel(Me).Value = NewValue 
End Sub

Disregard my previous post. Didn’t realize PagePanel has a ‘Value’ property.

Thanks Andrew, I thought about that last night, but it was late. I do want to override the standard PagePanel Value property so that the new control is a direct replacement for the old one and simply setting “UseFaderEffect = True” results in the animation. I’ll give that a try. Cheers.

So overriding as a pair of Methods doesn’t work either.

Function Value() As Integer
  Return Super.Value
End Function

Sub Value(Assigns newValue As Integer)
  
  If value <> Super.Value Then
    
    If UseFadeEfect Then
      
      Dim o As FadingInterfaceFx
      
      o = New FadingInterfaceFx(Self.Left + Me.Left, Self.Top + Me.Top, Me.Width, Me.Height , True)
      o.MakeScreenshot
      Super.Value = value
      o.Show
      
    Else
      
      Super.Value = value
      
    End If
    
  End If
End Sub

The error is “This item does not exist” for every instance of Super.Value in the code. I use Super.Constructor and Super.Destructor in plenty of other classes in my code, but not none of them are controls. Any other ideas?

Success!

Andrew after reading your reply more closely, casting the instance as a standard PagePanel was exactly what I need to do. Seems odd that you can’t simply use the “Super” keyword as you can with normal classes, but now I have a PagePanel control that can be set to fade in/out when changing pages by simply setting the appropriate property. Cool? Certainly. But I’m not sure if I’ll actually use it, the effect gets a bit tiring after using it a while. Here’s the end result:

UseFadeEfect As Boolean

Property Value As Integer

Get
  
  Return PagePanel(Me).Value
End Get

Set
  
  If value <> PagePanel(Me).Value Then
    
    If UseFadeEfect Then
      
      Dim o As FadingInterfaceFx
      
      o = New FadingInterfaceFx(Self.Left + Me.Left, Self.Top + Me.Top, Me.Width, Me.Height , True)
      o.MakeScreenshot
      PagePanel(Me).Value = value
      o.Show
      
    Else
      
      PagePanel(Me).Value = value
      
    End If
    
  End If
End Set

Thanks.

Has nothing to do with page panels in particular - it has everything to do with Super.PROPERTY vs Super.METHOD
You cannot reference a property using “Super.xxxxx” but you can reference a method
Properties are not virtual
Methods are