Hi,

I've been trying to use...
Code:
Dim myColour As Color = Color.FromName(TextBox1.Text)
...to give a user a choice of colour for Form background or, for example, Pen color.

I've run into a problem because 'Color.FromName' doesn't automatically detect an unknown colour or misspelling, if the text is unknown the code just returns Black.

Using...
Code:
     myColour = Color.FromName(TextBox2.Text)
     Me.BackColor = myColour
...however does produce a detectable error, and it's what I've been using.

In a previous thread jmcilhinney made this suggestion:
Quote Originally Posted by jmcilhinney View Post
vb.net Code:
  1. Dim names = {"Red", "Rid"}
  2.  
  3. For Each s In names
  4.     If [Enum].IsDefined(GetType(KnownColor), s) Then
  5.         Console.WriteLine($"There is a known colour named '{s}'.")
  6.     Else
  7.         Console.WriteLine($"There is NOT a known colour named '{s}'.")
  8.     End If
  9. Next
I can see how that would work but I don't really want to sit and add all 140 odd 'Known' colours to the string array 'names', not least because I can't type and produce far too many typo's at the best of times.

I've been trying, without success, to find where to access a 'look-up' list to compare the text with the known colours. I'm sure there must be a list somewhere in Visual Studio because a selection is presented each time a colour is selected in design.


Poppa