tonofsteel Posted August 26, 2003 Posted August 26, 2003 I have a picture box and the user can change the background color of it. I write the color to a file and then upon trying to load the string back into the color variable it says it cannot convert it. How do i do this the cheap and dirty way? Quote
*Experts* mutant Posted August 26, 2003 *Experts* Posted August 26, 2003 To convert a string to a color use this: System.Drawing.Color.FromName("string name") Quote
tonofsteel Posted August 26, 2003 Author Posted August 26, 2003 Thank you mutant. I also found the following method as well (after a lengthy search) for anyone else who ever comes across this problem: writeStream.WriteLine(this.BackColor.ToArgb()); Notice that we store the color as a string representation of the ARGB value. This will allow us to store any color, and successfully retrieve that color. If the color had been stored using the ToName() function, this would cause problems if the colour was anonymous as it would not be easy to read back in (try it!). Finally, we convert the string representation of the color back to a usable Color object using the FromArgb() function. this.BackColor = Color.FromArgb(System.Int32.Parse(readStream.ReadLine())); Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.