|
-
Sep 25th, 2020, 09:22 AM
#1
[RESOLVED] Problem with Color.FromName
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:
 Originally Posted by jmcilhinney
vb.net Code:
Dim names = {"Red", "Rid"}
For Each s In names
If [Enum].IsDefined(GetType(KnownColor), s) Then
Console.WriteLine($"There is a known colour named '{s}'.")
Else
Console.WriteLine($"There is NOT a known colour named '{s}'.")
End If
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
Along with the sunshine there has to be a little rain sometime.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|