ElektroStudios
ElektroStudios

Reputation: 20474

Cannot set some values of an usercontrol from the VS properties Window

In a Winforms usercontrol I've integrated a ProgressBar into a Listview, this is one of the properties:

''' <summary>
''' The ListView ProgressBar BorderColor
''' </summary>
Public Property ProgressBar_BorderColor As Pen
    Get
        Return _progressBar_bordercolor
    End Get
    Set(ByVal value As Pen)
        _progressBar_bordercolor = value
    End Set
End Property

Well, the problem is that in the properties window I can't change the pens and brush values.

I can change the values manually writting the code, but not in the properties window.

I did something wrong when coding the properties or just these kind of values cannot be changed in the properties window of any other control and not only my control? and why?

What I need to modify to be able to change these values in the properties window of my user control?

enter image description here

Upvotes: 0

Views: 282

Answers (2)

It would be better to create your GDI objects when used so you can properly dispose of them:

Using g as Graphics = Graphics.FromWhereEver, 
           P as New Pen(ProgressBar_BorderColor), 
           Br as New SolidBrush(ProgressBar_BackColor)

    ... draw and paint
    ... paint and draw
End Using          ' Graphics, Pen and Brush properly disposed of

It wont make a great deal of difference because I doubt you would sit and change colors back and forth as a hobby, but they aren't being disposed of when a new color value is set.

Upvotes: 1

ElektroStudios
ElektroStudios

Reputation: 20474

Solution:

· Brush to Color <> Color to Brush

Private _progressBar_backcolor As SolidBrush = New SolidBrush(Color.Red)

Public Property ProgressBar_BackColor As Color
    Get
        Return _progressBar_backcolor.Color
    End Get
    Set(ByVal value As Color)
        _progressBar_backcolor = New SolidBrush(value)
    End Set
End Property

· Pen to Color <> Color to Pen

Private _progressBar_bordercolor As Pen = New Pen(Color.LightGray)

Public Property ProgressBar_BorderColor As Color
    Get
        Return _progressBar_bordercolor.Color
    End Get
    Set(ByVal value As Color)
        _progressBar_bordercolor = New Pen(value)
    End Set
End Property

enter image description here

Upvotes: 1

Related Questions