我想所有的刷子的循環,這基本上是僞代碼,這將解釋什麼是我想要做的事:通過「刷」
For Each B in Brushes
'Something with Brushes
End For
刷是一種類型,但這樣我怎麼就能夠要做到這一點?
我想所有的刷子的循環,這基本上是僞代碼,這將解釋什麼是我想要做的事:通過「刷」
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())
+1遠比我的答案好 – 2011-06-15 06:17:38
你能做到這一點嗎?
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
Colorname是我想要的,謝謝你:D! – 2011-06-14 22:48:30
@Thomas如果顏色是你想要的,你應該枚舉顏色枚舉而不是畫筆,請檢查我的答案。 – Magnus 2011-06-14 22:52:30
我需要畫筆,我指的是他的變量名colorName :) – 2011-06-14 23:41:25
所有刷子添加到列表並循環訪問 – 2011-06-14 21:30:10