preserve custom property value

I am extending PictureBox control and added the following code

    Private clrForeColor As Color = Color.Black

    <Browsable(True)> _
    Overrides Property ForeColor() As Color
        Get
            Return clrForeColor
        End Get
        Set(ByVal Value As Color)
            clrForeColor = Value
            MyBrush.Color = clrForeColor
            Me.Invalidate()
        End Set
    End Property

Whe I change my ForeColor property from the property window the color changes but when executing the application the color rturns to black. How o solve this problem?
f_asmaaAsked:
Who is Participating?
 
RonaldBiemansConnect With a Mentor Commented:
Hi, call the base class forecolor

<Browsable(True)> Public Overrides Property ForeColor() As Color
        Get
            Return clrForeColor
        End Get
        Set(ByVal Value As Color)
            clrForeColor = Value
            MyBrush.Color = clrForeColor
            Me.Invalidate()
'*****
            MyBase.ForeColor = Value
'*****
        End Set
    End Property
0
 
arif_eqbalCommented:
That's because your code executes only at run time

I think you need to create a custom control for that, extend the picture box using a new Windows Control Library Project and adding your code then use this new control.

0
 
f_asmaaAuthor Commented:
What do you mean by executing the code at run time??????
0
 
arif_eqbalCommented:
How have you extended the Picture Box Control
It must be a class within your project

However when you access the property pages it is the basic PictureBox control isn't it
And not your extended class



0
 
f_asmaaAuthor Commented:
No I see the additional property that I added. I added a control library project to my application and added referenc to from my application.
0
All Courses

From novice to tech pro — start learning today.