Jump to content
Xtreme .Net Talk

Recommended Posts

Posted
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?
Posted

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())); 

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...