0

在 Winforms 用户控件中,我将 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

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

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

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

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

在此处输入图像描述

4

2 回答 2

1

解决方案:

·刷到颜色<>颜色到刷

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

·笔到颜色<>颜色到笔

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

在此处输入图像描述

于 2013-10-21T18:26:40.427 回答
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

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

于 2013-10-21T21:36:41.967 回答