如何解决遍历“画笔”
| 我想获取所有的Brushes,这基本上是伪代码,它将解释我正在尝试执行的操作:For Each B in Brushes
\'Something with Brushes
End For
刷子是一种类型,那么我该怎么做呢?
解决方法
不使用反射:
Dim brushes = [Enum].GetValues(GetType(KnownColor)) _
.Cast(Of KnownColor)() _
.Where(Function(k) k >= KnownColor.Transparent AndAlso k < KnownColor.ButtonFace) _ \'//Exclude system colors
.Select(Function(k) New SolidBrush(Color.FromKnownColor(k)))
编辑(从托马斯评论)
获取颜色名称(用于画笔)
Dim brushColorNames = [Enum].GetValues(GetType(KnownColor)) _
.Cast(Of KnownColor)() _
.Where(Function(k) k >= KnownColor.Transparent AndAlso k < KnownColor.ButtonFace) _ \'//Exclude system colors
.Select(Function(k) k.ToString())
, 你能做这个吗?
dim brush as new Brush() \'needs a proper brush instance,not sure where there is one,so this line won\'t work
Dim type As Type = GetType(System.Drawing.Brushes)
Dim properties As PropertyInfo() = type.GetProperties(BindingFlags.Static)
For Each [property] As PropertyInfo In properties
Console.WriteLine(\"{0} = {1}\",[property].Name,[property].GetValue(brush,Nothing))
Next
, 这取决于您要如何使用画笔。
For Each b in GetType(Brushes).GetProperties
Dim colorName = b.Name \' If you want color names (AliceBlue through YellowGreen)
Dim brushValue = b.GetValue(Nothing,Nothing) \' Gives you a Brush
Dim brushColor = brushValue.Color \' Gives you the hex color of the brush (AliceBlue = #FFF0F8FF)
Next
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。