Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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?

Dodge

Grab Life By The Horns

  • Moderators
Posted

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}

Visit...Bassic Software
  • *Experts*
Posted

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).

"Being grown up isn't half as fun as growing up

These are the best days of our lives"

-The Ataris, In This Diary

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...