The property value needs to be cloned/copied in the property-page form/editor and in the Property procedure setter. Then the modification is honored at run time.
When a host project changes a property of my custom control at design time, the change isn't honored at run time. Why?!
WHAT I HAVE:
Visual Basic 2019, .NET Framework 4.0+/.NET Core, WinForms
MY PROBLEMS:
I've created an extended custom control that uses a property page (using my own property-page form and editor classes) to allow a host project to modify a property of custom type (defined by my own class/structure) and/or group type (based on an array, list, collection, dictionary, etc.) at design time. The changes made by a host project remain intact when the project is exited and reloaded, provided the design-time value of the property in question isn't tied to the design-time value of another. However, the design-time changes are not reflected in the control when it's loaded at run time! Instead, the initial value is whatever defaults I've initialized it to in the declarations section of the control's class. How can I pre-define initial values for a property (when an instance of the control is first dropped on a host project's form), but have any host-project design-time changes endure not only on project reload, but also on project run? (BTW, I'm not using a pre-defined property editor like CollectionEditor. I'm defining my own classes for property-page form and editor.)
Basically, if my control defines a property to have an initial value of Value1, and a host project modifies the property to Value2 using my property page, Value2 is henceforth the design-time value ever after in any given session of the host project; however, whenever the project runs, the property reverts to Value1 until changed at run-time. (BTW, if the property is not of a custom/group type, and does not have a custom property page, this problem doesn't exist. The run-time value then starts as Value2.)
Please give any answer in VB.NET, and keep it as simple as possible.
Example:
Public Class MyType 'could be a structure instead
Public Property SubProperty1 As Type1
Public Property SubProperty2 As Type2
Public Property SubProperty3 As Type3
' other sub-properties may follow
' optional method:
Public Sub ToString() As String
' some code
Return StringToDisplay
End Sub
End Class
Public Class MyControl
Inherits OtherControl 'could by UserControl or an existing control
Private MyTypeVar As MyType = original-value
Private MyGroupType As MyGroupType = original-group-value 'MyGroupType is related to an array, list, collection, dictionary or other serializable type for a bunch of items either of a standard type or of MyType
<Editor(MyTypeEditor, GetType(UITypeEditor))> _
Property MyProperty() As MyType
Get
Return MyTypeVar
End Get
Set (value As MyType)
MyTypeVar = value
End Set
End Property
<Editor(MyGroupTypeEditor), GetType(UITypeEditor))> _
Public MyGroupProperty() As MyGroupType
Get
Return MyGroupTypeVar
End Get
Set (value As MyGroupType)
MyGroupTypeVar = value
End Set
End Property
' other properties/methods/events may follow
End Class
How can I ensure that the initial run-time values of MyProperty and MyGroupProperty in a host-project control instance aren't always original-value and original-group-value, respectively, if these properties are changed in the host project at design time?