0

I have this code in Visual Basic working fine which saves a color that is selected from a ComboBox.text to My.Settings which is set to system.drawing.color.

    My.Settings.SpecialColor = Color.FromName(ComboBoxSpecialColor.Text)

I am having trouble converting back to the ComboBox.text the color from the saved color in My.Settings.

  ComboBoxSpecialColor.Text = My.Settings.SpecialColor(ToString)

I actually found a way for combo box to work but I was using lots of If else statements and typing in each color string to choose from. I was hoping there was an easier way because I have about 10 colors to select from in each combo box which i have 5 combo boxes and it was going to take about 50 if then else end if statements.

Does anyone know how to convert the my.settings color back to a string which can be placed in the combobox.text to display the right color?

Darryl
  • 45
  • 1
  • 7
  • How does `My.Settings.SpecialColor.ToString()` not do what you want? Whats in the combo, the names like `AliceBlue`? – Ňɏssa Pøngjǣrdenlarp Feb 21 '16 at 15:55
  • Plutonix, thank you so much. You answered my question by asking how does it not work. I must have been half asleep because I had the ( ) in the wrong place. Also, yes there are names like AliceBlue in the combo. – Darryl Feb 21 '16 at 18:50
  • Well, I tried the My.Settings.SpecialColor.ToString() and thought that was going to work but the combo selection is showing the words "Color [AliceBlue]". I need it to just show AliceBlue. Is there any way to get rid of the word Color and the bracketts surrounding AliceBlue so it just shows AliceBlue in the combo selection? – Darryl Feb 21 '16 at 19:12
  • The Color structure has a `Name` property that you can use instead of the method `ToString()`. – TnTinMn Feb 21 '16 at 21:47
  • @TnTinMn Thank you. The `Name` property works great! – Darryl Feb 21 '16 at 23:12

1 Answers1

0

This might point you in the right direction by removing parts of the string https://msdn.microsoft.com/en-us/library/txha70f6(v=vs.90).aspx

user1234433222
  • 976
  • 2
  • 10
  • 21