vb.net - 如何获得自定义笔颜色?
问题描述
我试过了,但它在这里不起作用是我的代码:
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))
推荐阅读
- azure-devops - 如何在 Azure DevOps 上的发布管道中添加插槽交换任务之前的批准
- java - 过滤给定集合元素的增量条件
- ionic4 - 如何动态转到上一页(离子4)?
- javascript - 为什么为破坏变量未定义
- docker - 进程一直挂着
- typescript - 如何选择对象的字符串成员
- c - 基于相同的对齐和/或表示,一个对象的大小是否等于另一个对象的大小?
- java - Java 马尔可夫链
- r - R-如何组合具有相同列名但顺序不同的两个数据框
- flutter - 输入时光标默认为文本字段的开头,使用 TextEditingController + onChanged - Flutter