Making a color .txt file

I'm writing a program that at launch checks to see if a file exist. Inside the file will be what color items need to be what color:

When color is originally assigned:
1
2
3
4
5
6
	
 colorDialog1->ShowDialog();
 ColorControl->BackColor = colorDialog1->Color;
  	 button1->BackColor = ColorControl->BackColor;
	 button2->BackColor = ColorControl->BackColor;
	 button3->BackColor = ColorControl->BackColor;


But how do I get the the color to list the color of item (in this case button) in a textBox?
 
textBox1->Text = button1->BackColor->Text

I realize this isn't a proper syntax, I'm asking what is?
Every .Net class supports the ToString() method. See if you can use it. But really the most appropriate way would be to get the class' type converter (the class here being Color) and convert to string. You would then use the same type converter to convert from string.
Would mind a quick simple example. The string way works, but it gives me a textBox that looks like this:

1
2
3
4
5
6
textBox1->Text = button1->BackColor.ToString();
//-------------------------
// textBox1->Text = :
// 
//  Color [A=255, R=0, G=128, B=255]
//  
I was thinking something like this (in C#, but I bet you can convert it to C++/CLI):

1
2
3
4
5
6
7
TypeConverter tc = TypeDescriptor.GetConverter(typeof(Color));
if (tc.CanConvertTo(typeof(string)))
{
    //This is the string you need to save in your text file, and you need to read it back as a whole
    //and pass it to the type converter again, except using ConvertFrom() instead of ConvertTo().
    string strColor = (string)tc.ConvertTo(button1.BackColor, typeof(string));
}


NOTE: While I was trying to remember how to work with colors, I found two more classes of interest: A ColorConverter class (which might be the same as the type converter in the code), and a ColorTranslator class. They might also prove useful to you.
Last edited on
Topic archived. No new replies allowed.