Is it possible to reduce an object down to its base class? To illustrate what I mean, the idea in the following code would be that the programme stops beeping after the button is pressed because the class2 object is reduced to a class1 object, which doesn't beep. But it doesn't work. Any ideas?
Visual Basic:
Public Class Form1
Dim j1 As class1
Dim j2 As class2
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim j2 As New class2(Me)
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'Get rid of the class2 object, I just need the class1 "core" of it now.
j1 = CType(j2, class1)
j2 = Nothing
End Sub
End Class
Public Class class1
'This class sets the text of the form to the x position of the mouse when the mouse moves.
Public WithEvents f As Form1
Public v As Long
Private Sub f_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles f.MouseMove
f.Text = e.X
End Sub
Sub New(ByVal ff As Form1)
f = ff
End Sub
End Class
Public Class class2
'This class inherits class1 and beeps when the mouse moves over the form.
Inherits class1
Sub New(ByVal ff As Form1)
MyBase.New(ff)
End Sub
Public gh As Long
Private Sub f_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles f.MouseMove
Beep()
End Sub
End Class