How do I change the brush colour so that each square is different
I was thinking of using an array,
Dim arrCol() As String = {"Red", "Yellow", "Green"} but string can't be converted to system.brush. I tried Dim arrCol as System.Brushes, but that doesn't work either.
So any ideas please.
Here's the code,
Dim B1 As New Bitmap(146, 92)
Dim G1 As Graphics = Graphics.FromImage(B1)
Dim PB As New PictureBox
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim X, Y, W, i As Integer
X = 0
Y = 0
W = 128
For i = 1 To 40
G1.FillRectangle(Brushes.Blue, X, Y, 16, 16)
X += 18
If X > W Then
X = 0
Y += 18
End If
Next
G1.Dispose()

Different Coloured Brushes
eligh_ll
montechristo
Try working with Brush as it is a Brushes.
favio
I do appreciate your help, but maybe you could show me, how, what your doing works with the code sample I first posted, as I'm obviously missing something
DQM
Nothing much it's just referring to comments in another thread:
http://forums.microsoft.com/MSDN/ShowPost.aspx PostID=1203258&SiteID=1
BTW - good to see you've got your link pasting sorted out.
noviceneedhelp
Dim
Br As Brush = New SolidBrush(Color.FromArgb(122345))I did choose from argb because if you can set it to an argb color you can set it to anything.
adamb99
jankowiak
Dim arrPallete() = {123, 89, 7, 21, 11}
Label.BackColor = Color.FromKnownColor(arrPallete(counter))
Cheers
Graham
Huson
Krutika
But that doesn't seem to work.
spydude777
Graham
The following will give you an array of known colours.
Dim Colours() As KnownColor
Colours = DirectCast([Enum].GetValues(GetType(KnownColor)), KnownColor())
You could then use Color.FromKnownColor to set the colour of your brush by picking a colour from the array.
Is that about 80% Renee
lsproc
It sure works here. "{Name=1dde9, ARGB=(0, 1, 221, 233)}" That's the color output from the debugger.
kholling
manjunath cv
As dave demonstrates, create an array of brushes. Pick an index from that array.
You can start of by simply hard-coding it, to get a feel for what you want (specifically, do you know what colors you want to show ).
Dim theBrush(0 To 9) As Brush
theBrush(0) = New SolidBrush(Color.FromArgb(&HFF, &HFF, &H0, &HFF))
theBrush(1) = New SolidBrush(Color.FromArgb(&HFF, &HFF, &H0, &H0))
theBrush(2) = New SolidBrush(Color.Cyan)
' etc...
Do you see what Renee said in the first post about using the Brush instead of Brushes
Start simple (e.g. hard code an array), understand the concept of how things work, then move on to a better perfoming, more elegant solution. Personally, I have a class which creates an array of Pens and Brushes from my fixed colors which I use in a variety of projects - and it simply creates an array like the above example.
(looks like I stomped on something, here...)
Cato1969
to someone like me..thats about 12 and a half %.....