画笔颜色
Brushes to Colors
嘿,我在做一个 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 属性 这样的:
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 上使用 "new param"。
- 这是唯一的方法还是可能有其他解决方案?
已解决:
我调整了我的项目:
<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
你有点找错树了。
您不想将画笔变成一种颜色,您想要将现有画笔的颜色 属性 设置为新值。
所以当你第一次制作画笔时,你做了这样的事情:
Dim mybrush As New SolidBrush(Color.Aqua)
然后你想设置颜色
mybrush.Color = Color.Azure
如果你想获取画笔的颜色,那么你可以这样做:
Dim myColour As New Color
myColour = mybrush.Color
嘿,我在做一个 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 属性 这样的:
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 上使用 "new param"。
- 这是唯一的方法还是可能有其他解决方案?
已解决:
我调整了我的项目:
<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
你有点找错树了。
您不想将画笔变成一种颜色,您想要将现有画笔的颜色 属性 设置为新值。
所以当你第一次制作画笔时,你做了这样的事情:
Dim mybrush As New SolidBrush(Color.Aqua)
然后你想设置颜色
mybrush.Color = Color.Azure
如果你想获取画笔的颜色,那么你可以这样做:
Dim myColour As New Color
myColour = mybrush.Color