【发布时间】:2015-02-26 11:44:54
【问题描述】:
嘿,我正在做一个 VisualBasic Windows 窗体控件项目,但遇到了一个小问题:
这是我的 OnPaint 方法:
Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
MyBase.OnPaint(e)
Dim g As Graphics
g = e.Graphics
Dim ancho As Integer = Me.Width / 2
Dim alto As Integer = Me.Height / 2
_posiciox = 5
Percentatge(_maxim,_minim)
For Index As Double = 0.1 To 10.0
If Index <= _percent Then
If Index >= 9 Then
g.FillRectangle(_color4, _posiciox, alto - 10, 40, 20)
ElseIf Index >= 8 Then
g.FillRectangle(_color3, _posiciox, alto - 10, 40, 20)
ElseIf Index >= 6 Then
g.FillRectangle(_color2, _posiciox, alto - 10, 40, 20)
Else
g.FillRectangle(_color1, _posiciox, alto - 10, 40, 20)
End If
End If
g.DrawRectangle(Pens.Black, _posiciox, alto - 10, 40, 20)
_posiciox = _posiciox + 45
Next
End Sub
填充颜色的地方是 Brushes.Color 参数。我也想让用户选择这个颜色。
我尝试过这样的公共财产:
Public Property ColorBaix() As Color
Get
Return Color.Coral
End Get
Set(ByVal value As Color)
End Set
End Property
但我无法将 Brushes.Color 转换为 Color.Color:
我找到了一些示例Colors to Brush,但由于过载问题,我无法在 OnPaint 上使用“新参数”。
- 这是唯一的方法还是可能有其他解决方案?
已解决:
我调整了我的项目:
<Description("Color Primari")>
Public Property ColorBaix() As Color
Get
Return color1
End Get
Set(ByVal value As Color)
color1 = value
_color1 = New SolidBrush(value)
Invalidate()
End Set
End Property
【问题讨论】:
标签: vb.net visual-studio-2010 vba