Dodgeram01 Posted February 22, 2003 Posted February 22, 2003 Is there a way to save the back color of a textbox in the same format everytime? Sometimes it will save the color as Color [Red] And sometimes it will save it as Color [A=255, R=82, G=226, B=180]. I need to be able to read this string and convert it to the type system.drawing.color, which I can do. My problem is I can't do this if I don't know what format the color will save in. Is there any easy way around this, or will I have to play around with seeing what format it is in and then formatting it how I need it? Quote Dodge Grab Life By The Horns
Moderators Robby Posted February 22, 2003 Moderators Posted February 22, 2003 You can use FromArgb and ToArgb.... Me.BackColor = Color.FromArgb(255, 0, 0)'simulate a color change Dim x As Color = Me.BackColor ' get the color value of a control into x MessageBox.Show(x.ToArgb.ToString)' use this to save the value as a string textbox1.BackColor = x 'since x is already of type Color, we can assign it to a control [edit] 'to pu it simply, use this method to save the color value... Me.BackColor.ToArgb.ToString() [end Edit} Quote Visit...Bassic Software
*Experts* Bucky Posted February 22, 2003 *Experts* Posted February 22, 2003 If you're serializing and deserializing the textbox using the standard XML serialization classes, then I would think that the deserializer would handle all this for you. But to answer your question, you can use two methods of the Color class to get the color. If the string contains a number, then it must be ARGB values, and you can parse out the color value and create a color from the Color.FromArgb() method. If there aren't any numbers, then it must be a named color, and the Color.FromName() method will retrieve the correct color based on the known color name ("Red" in this case). Quote "Being grown up isn't half as fun as growing up These are the best days of our lives" -The Ataris, In This Diary
Dodgeram01 Posted February 22, 2003 Author Posted February 22, 2003 Thanks guys! EXACTLY what I needed. Quote Dodge Grab Life By The Horns
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.