I've been working on a project to help myself better understand how inherited
classes work. I think I've learned more about classes by doing this than any
other effort I've made.
I've tried to create a simple problem by creating a class named TestThis
that inherits System.Windows.Forms.Form and then adding one shared procedure
to this. I set the form to inherit TestThis instead and it gets everything
plus the one procedure that I've given it. So far so good. My problem is
trying to have TestThis dynamically set a form property through inheritance.
It's easy to have my form set this property but for education purposes I'm
doing it the hard way because I want the class to be able to do this. As you
can see below Me causes problems as well as MyBase, MyClass etc. I'm trying
to address Form1 this way without actually calling its name. how do I do
this? Let me show you some code:
Public Class TestThis
Inherits System.Windows.Forms.Form
Public Shared Sub Fade(ByVal Value As Integer)
If Value < 0 Then
Value = 0
ElseIf Value > 100 Then
Value = 100
Else
Value = Value / 100
End If
Me.Opacity = Value ' <- ME causes problems.
End Sub
End Class
' Just create a new form. nothing special. change the inheritance and add
the event handlers.
Public Class Form1
Inherits FadeTest
'+ " Windows Form Designed Generated Code " ' nothing changed here
Private Sub Form1_Activated(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.Activated
Me.Fade(100)
'Me.Opacity = 1
End Sub
Private Sub Form1_Deactivate(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.Deactivate
Me.Fade(50)
'Me.Opacity = 0.5
End Sub
End Class