[RESOLVED] Read custom colors from a file , then load custom colors into color dialog box.
Code:
Dim ColorDialog1 As New ColorDialog
Dim cMyCustomColors(16) As Color
'read custom colors out of file and load into custom color array
If IO.File.Exists(My.Application.Info.DirectoryPath & "\customcolors2.ini") Then
' Step 1: read lines from the file.
For Each line In File.ReadLines(My.Application.Info.DirectoryPath & "\customcolors2.ini")
' Step 2: separate each line on the comma char.
Dim parts = line.Split(","c)
' Step 3: print out the parts of the line.
For Each value In parts
cMyCustomColors(parts(0)) = Color.FromArgb(parts(1), parts(2), parts(3)) 'RGB color values
Next
Next
End If
'Convert colors to integers
Dim colorBlue As Integer
Dim colorGreen As Integer
Dim colorRed As Integer
Dim iMyCustomColor As Integer
Dim iMyCustomColors(cMyCustomColors.Length - 1) As Integer
For index = 0 To cMyCustomColors.Length - 1
'cast to integer
colorBlue = cMyCustomColors(index).B
colorGreen = cMyCustomColors(index).G
colorRed = cMyCustomColors(index).R
'shift the bits
iMyCustomColor = colorBlue << 16 Or colorGreen << 8 Or colorRed
iMyCustomColors(index) = iMyCustomColor
Next
ColorDialog1.CustomColors = iMyCustomColors
If ColorDialog1.ShowDialog() = DialogResult.OK Then
' Me.BackColor = ColorDialog1.Color
End If
The file values for all 16 boxes as index, RGB values in comma delimited file called 'customcolors2.ini'