I'm looking for a way to implement a property change event for a object class. Whenever a certain value changes it needs to recalculate the items mass.
I have searched some topic's and may have found a solution, only problem for me is that c#
is unreadable for me ( for now ).
After doing some more digging, if also found a vb.net solution, in the answer they refer to MSDN page. But the sample there is removed.
I also found this page
How to: Implement Property Change Notification
But if I check the current framework it read: "This topic is no longer available"
So my guess something has changed for this event during changing of framework? Or is this still the active method to do this as described in the vb.net solution?
Add code of class
Public Class BodyComponent
' Basic properties that are required for all of the bodycompenents
' regardless of the type.
<Browsable(True)> Public Property Type()
<Browsable(True)> Public Property Height() As Double
<Browsable(True)> Public Property Thickness() As Double
<Browsable(True)> Public Property Elevation() As Double
<Browsable(True)> Public Property Auto_Diameter() As Boolean
<Browsable(True)> Public Property Diameter() As Double
<Browsable(True)> Public Property Mass() As Double
' Type Enum that defines what kind of body component is created.
Public Enum BodyComponentType
Cylinder = 0001
Cone_reduction = 0002
End Enum
and the derived class
Public Class Body_Cylinder
' Get the base properties
Inherits BodyComponent
' Set new properties that are only required for cylinders
Public Property Segments() As Integer
Public Property LW_Orientation() As Double
Public Shared Count As Integer = 0
Public Sub New()
count = count + 1
End Sub
' Remove Cylinder from collection and change the count
Public Shared Sub delete_cylinder(ByVal oItem As Integer, ByRef oBinding As BindingSource)
oBinding.RemoveAt(oItem)
Count = Count - 1
End Sub
' Calculate mass
Private Sub Calc_mass()
' HACK: create material list where rho is defined for other
' material types
Dim rho As Double
rho = 8
Dim oVolume As Double
oVolume = Math.PI / 4 * ((Diameter + 2 * Thickness) ^ 2 - Diameter ^ 2) * Height
Mass = oVolume * rho
End Sub