Store Colors in Database in VB .net

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have an application that enables the user to change the color of the form
(pretty simple). I want that color to be saved to a DB when the form is
closed. Then, when the form is opened again, I want it to get that color from
the DB, and have its background with that color.

The problem is that VB.net stores the colors as a COLOR type, and to store
it in a DB I need to have it as string or integer. And after that, I need to
be able to assign whatever is in the database to the form.backcolor.

I would appriciate any help in the matter.
Thank you.
 
There are several ways. You can store the color name (Color.Name) in the
database as a string, then use the Color.FromName method to get it back
later, or use the Color.ToStrng method to store the color in the database as
a string. That looks like "Color [Blue]," or for unnamed colors, something
like "Color [A=255, R=20, G=45, B=206]." Color.FromName works with that
value as well as the Name property value to re-create the color later. You
could also store the color as an integer in the database using the
Color.ToArgb and recreate it with the Color.FromArgb method later. In my
opinion, the latter is better, because it's smaller and probably faster as
well. Finally, you can use the System.Drawing.ColorTranslator class to
translate colors to and from various representations.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top