Custom Class Properties

bufer24

Active member
Joined
Mar 27, 2008
Messages
35
Programming Experience
3-5
Hi, I have trouble with this:
I have a simple class:
VB.NET:
Expand Collapse Copy
Public Class MyClass
  dim _prop as new MyProp()
  Public Property Prop as MyProp
    Get
       Prop=_Prop
    End Get
    Set(value as MyProp)
       _Prop=value
      .... I need to trigger other procedures here, but it doesn´t work
    End Set
  End Property
end class

Public Class MyProp
  ...some public properties
  Public property SomeProperty as Integer 
  ...
end Class

At runtime I declare an instance of MyClass and I change some of its properties, like this:
MyClass.Prop.SomeProperty=2.
I need to capture this property change, but I don´t know how. I thought that I sholud put the capture after "_prop=value", but the Set/End Set block of MyClass doesn´t execute at all when I change property value.
 
I'm guessing, but surely if you want to catch MyClass.Prop.SomeProperty=2, you'd have to watch for this change in the MyProp class.
VB.NET:
Expand Collapse Copy
Public Class MyProp
  Private _SomeProperty as integer

  Public property SomeProperty as Integer 
    Get
       return _SomeProperty
    End Get
    Set(value as integer)
       _SomeProperty = value
      'put your code here
    End Set
  End Property

end Class

I would think that your Set/End Set of MyClass will trigger if you do
VB.NET:
Expand Collapse Copy
Dim NewProp as New MyProp
MyClass.Prop = NewProp

Hope that makes sense - it's been a long day :(
 
yes, that´s true, but what if there are several instances of MyProp class? I want to use 2 instances of myprop in MyClass. MyProp has to be universal.
Here is one example what I want to achieve: my usercontrol draws a circle and a rectangle (using graphics). Both circle and rectangle have a border. The border is determined by width and color. So I wanted to make a universal Border Class that has two properties: color and width and use this class for the circle and the rectangle as their properties.
When I put the usercontrol onto my form, I want to be able to edit the properties of rectangle and circle at designtime and at runtime. The design-time property list of my usercontrol should look like on the picture in the attachment to this post.
At this time, I can see and edit the properties at design or at runtime, but with no effect. For example: at design time I change the width property. After this, the usercontrol should redraw the circle using the modified border. How should I trigger the drawing function?
 

Attachments

  • sample.jpg
    sample.jpg
    43.1 KB · Views: 51
Last edited:
here is another example of my "quest for working expandable property":

VB.NET:
Expand Collapse Copy
Imports System.ComponentModel

Public Class MyUC
    Private _Border As New MyBorder()

    Public Property Border() As MyBorder
        Get
            Border = _Border
        End Get
        Set(ByVal value As MyBorder)
            _Border = value
            mylabel.Text = _Border.Width 'this doesn´t execute at all. WHY?
        End Set
    End Property

    Private Sub MyUC_Resize(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Resize
        mylabel.Text = _Border.Width
    End Sub
End Class

<TypeConverter(GetType(ExpandableObjectConverter))> _
Public Class MyBorder
    Private _Width As Integer = 1
    'Public Color As Color '= Color.Black

    <NotifyParentProperty(True), _
    RefreshProperties(RefreshProperties.All)> _
    Public Property Width() As Integer
        Get
            Return _Width
        End Get
        Set(ByVal value As Integer)
            _Width = value
        End Set
    End Property
End Class

It is a simple usercontrol with a label on it (mylabel), which displays the Border.Width property. As you can see on the attached picture, as I put the usercontrol on my form, I can edit the Width property, but the label text doesn´t update. The question is: why, and how can I make it update at design-time? When I change the Border.Width property it only updates the label text after I resize the usercontrol.
As you can see, there is also a button on the form. I put this code into the click routine of the button: MyUC1.Border.Width=10. When I click the button at runtime, the label in my usercontrol also doesn´t update.
 

Attachments

  • sample1.jpg
    sample1.jpg
    46.7 KB · Views: 46
I´ve tried that, but no effect. It seems that the Set/End Set block of the Border property doesn´t execute at all. I´ve put a breakpoint there and it didn´t stop.
The strange thing about it is, that when I change the property at design time and start the application, the label updates to a proper value. But when I click the button at runtime, it doesn´t change.
 
Back
Top