如何获得自定义笔颜色?

索马索姆

我试过了,但它在这里不起作用是我的代码:

Private Sub PictureBox3_Paint(sender As Object, e As PaintEventArgs) Handles PictureBox3.Paint
    Dim pencolor As String
    pencolor = "89; 179; 105"
    Dim s(1) As Integer
    Dim f(1) As Integer
    Dim pen As Pen = Pens.pencolor
End Sub

谢谢!

杰夫

为了在您的笔上使用自定义颜色,您需要先为您的笔创建画笔。

对于此示例,我假设 RGB 颜色值是字符串中的序列。

    Dim r As Integer = 89
    Dim g As Integer = 179
    Dim b As Integer = 105
    Dim customColour As Color = Color.FromArgb(r, g, b)
    Using customBrush As New SolidBrush(customColour)
        Using customPen As New Pen(customBrush)
            ' use the custom pen...
        End Using
    End Using

使用自定义颜色创建画笔,然后使用画笔创建自定义笔。当您使用 Pen 时,它将采用您由其 R、G、B 值定义的颜色

编辑 (感谢 Ahmed Abdelhameed 关于另一个构造函数的提醒)

APen也可以在没有 Brush 的情况下创建,只需在其构造函数中指定所需的颜色:

Dim customPen As New Pen(Color.FromArgb(r, g, b))

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章