Just some BS code to illustrate the problem I'm having. The issue is with the change() sub under Color_Class (line 13). It gives the error:
"Reference to a non-shared member requires an object reference"
VB Code:
Public Class Form1 Friend WithEvents Button1 As myButton_Class Friend WithEvents Button2 As myButton_Class Class myButton_Class Inherits Button Public myColor As New Color_Class Class Color_Class Private _color As Color Sub change() BackColor = _color End Sub Property color() As Color Get color = _color End Get Set(ByVal value As Color) _color = value End Set End Property End Class End Class Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Button1.myColor.color = Color.Aqua Button1.myColor.change() Button2.myColor.color = Color.Blue Button2.myColor.change() End Sub Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Button1 = New myButton_Class Button1.Location = New System.Drawing.Point(100, 75) Button1.Size = New System.Drawing.Size(75, 25) Button1.Name = "Button1" Button1.Text = "Button1" Controls.Add(Button1) Button2 = New myButton_Class Button2.Location = New System.Drawing.Point(100, 125) Button2.Size = New System.Drawing.Size(75, 25) Button2.Name = "Button2" Button2.Text = "Button2" Controls.Add(Button2) End Sub End Class
How can I fix this error? I want to create "smart" properties that perform functions on themselves, but each has to be it's own instance since I can't share the storage... Clearly I'm missing something fundamental in my understanding of shared and instantiated...
Help?
-Andy.




Reply With Quote