Search code examples
vb.netcolorscomboboxmy.settingssystem.drawing.color

How can I convert system.drawing.color back to a string?


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?


Solution

  • 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