无法从VS属性窗口设置usercontrol的某些值

时间:2013-10-21 17:26:08

标签: c# vb.net winforms visual-studio-2012 user-controls

在Winforms usercontrol中,我已将ProgressBar集成到Listview中,这是其中一个属性:

''' <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

嗯,问题是在属性窗口中我无法更改笔和画笔值。

我可以手动编写代码来更改值,但不能在属性窗口中更改。

我在对属性进行编码时做错了,或者只是在任何其他控件的属性窗口中不能更改这些值,而不仅仅是我的控件?为什么?

我需要修改哪些内容才能在用户控件的属性窗口中更改这些值?

enter image description here

2 个答案:

答案 0 :(得分:1)

解决方案:

·刷到颜色&lt;&gt;要刷的颜色

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

·笔到颜色&lt;&gt;颜色到笔

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

答案 1 :(得分:1)

最好在使用时创建GDI对象,以便正确处理它们:

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

它不会产生很大的不同,因为我怀疑你会坐着来回改变颜色作为一种爱好,但是当设置新的颜色值时它们不会被处理掉。