Results 1 to 4 of 4

Thread: [RESOLVED] Read custom colors from a file , then load custom colors into color dialog box.

Threaded View

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Mar 2024
    Posts
    874

    Resolved [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'

    Code:
    0,139,155,184
    1,188,213,254
    2,115,172,183
    3,200,249,198
    4,189,194,253
    5,200,249,255
    6,108,213,210
    7,236,164,236
    8,40,181,124
    9,126,107,203
    10,189,87,162
    11,65,77,160
    12,143,143,143
    13,255,255,255
    14,255,255,255
    15,155,155,155
    Screenshot attached as the result
    Attached Images Attached Images  
    Last edited by sdowney1; Jun 16th, 2024 at 07:12 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width