Home All Groups Group Topic Archive Search About

Saving the Color value into a string

Author
20 Nov 2006 6:17 PM
Henry Jones
VB.NET Windows Forms VS 2005

I would like to give the user the option of changing the background color of
the textbox to anything they want.  Can someone provide code how to save the
textbox1.BackColor to a string and then convert it back to a color that I
can assign to the textbox?

I have looked at colorconverter class which can inherit from the
TypeConverter class and it's all too confusing.  I tried some examples and
just can't get it.

I tried something like this:

Dim myColor As Color = Color.PaleVioletRed

    ' Create the ColorConverter.
    Dim converter As System.ComponentModel.TypeConverter = _
       System.ComponentModel.TypeDescriptor.GetConverter(myColor)


and it works if the color is already set, but what if I want the user to
choose from the Color Dialog box?

HELP please

Author
20 Nov 2006 7:26 PM
RobinS
Why do you want to convert it to a string?

If you're trying to save the setting so you can apply it
later when they run the app again, you can save it as a
color type.

Robin S.
-----------------------------
Show quoteHide quote
"Henry Jones" <he***@yada.com> wrote in message
news:OlZxzANDHHA.4228@TK2MSFTNGP03.phx.gbl...
> VB.NET Windows Forms VS 2005
>
> I would like to give the user the option of changing the background color
> of the textbox to anything they want.  Can someone provide code how to
> save the
> textbox1.BackColor to a string and then convert it back to a color that I
> can assign to the textbox?
>
> I have looked at colorconverter class which can inherit from the
> TypeConverter class and it's all too confusing.  I tried some examples and
> just can't get it.
>
> I tried something like this:
>
> Dim myColor As Color = Color.PaleVioletRed
>
>    ' Create the ColorConverter.
>    Dim converter As System.ComponentModel.TypeConverter = _
>       System.ComponentModel.TypeDescriptor.GetConverter(myColor)
>
>
> and it works if the color is already set, but what if I want the user to
> choose from the Color Dialog box?
>
> HELP please
>
Author
21 Nov 2006 3:04 PM
Henry Jones
I wanted to convert it to a string to keep the users choice in a
configuration file with some other options.  How can I save it as a color
type to a table?

Thanks,

Henry

Show quoteHide quote
"RobinS" <RobinS@NoSpam.yah.none> wrote in message
news:4pmdnc-RManknP_YnZ2dnUVZ_tOdnZ2d@comcast.com...
> Why do you want to convert it to a string?
>
> If you're trying to save the setting so you can apply it
> later when they run the app again, you can save it as a
> color type.
>
> Robin S.
> -----------------------------
> "Henry Jones" <he***@yada.com> wrote in message
> news:OlZxzANDHHA.4228@TK2MSFTNGP03.phx.gbl...
>> VB.NET Windows Forms VS 2005
>>
>> I would like to give the user the option of changing the background color
>> of the textbox to anything they want.  Can someone provide code how to
>> save the
>> textbox1.BackColor to a string and then convert it back to a color that I
>> can assign to the textbox?
>>
>> I have looked at colorconverter class which can inherit from the
>> TypeConverter class and it's all too confusing.  I tried some examples
>> and just can't get it.
>>
>> I tried something like this:
>>
>> Dim myColor As Color = Color.PaleVioletRed
>>
>>    ' Create the ColorConverter.
>>    Dim converter As System.ComponentModel.TypeConverter = _
>>       System.ComponentModel.TypeDescriptor.GetConverter(myColor)
>>
>>
>> and it works if the color is already set, but what if I want the user to
>> choose from the Color Dialog box?
>>
>> HELP please
>>
>
>
Author
21 Nov 2006 5:51 PM
RobinS
You can save this information to the <Settings>
information for the project.

You can add this info by double-clicking on "my project"
in the solution explorer. This brings up the project
properties. Click on the <Settings> tab.

Add the settings here. Each setting must have a
unique name, such as ProductTextBoxColor,
CustomerTextBoxColor, etc.

For Type, set it to System.Drawing.Color.

Set the scope to User.

Then in your code, when the user changes it, save it to
the settings:

  My.Settings.ProductTextBoxColor = Color.PaleVioletRed

Then when you want to use it, use My.Settings.ProductTextBoxColor
instead of a color. It will retrieve the value from the Settings
and use it.

  ProductTextBox.BackColor = My.Settings.ProductTextBoxColor

The .Net runtime saves the settings when the application is
closed, and reads them when it is opened.

You can use the ColorDialog to allow the user to select
a color. I would save it to My.Settings at that point,
then turn around and assign it using My.Settings.ProductTextBoxColor;
this way you can ensure that it's working properly.

Robin S.

Show quoteHide quote
"Henry Jones" <he***@yada.com> wrote in message
news:eMVXZ5XDHHA.4464@TK2MSFTNGP06.phx.gbl...
>I wanted to convert it to a string to keep the users choice in a
>configuration file with some other options.  How can I save it as a color
>type to a table?
>
> Thanks,
>
> Henry
>
> "RobinS" <RobinS@NoSpam.yah.none> wrote in message
> news:4pmdnc-RManknP_YnZ2dnUVZ_tOdnZ2d@comcast.com...
>> Why do you want to convert it to a string?
>>
>> If you're trying to save the setting so you can apply it
>> later when they run the app again, you can save it as a
>> color type.
>>
>> Robin S.
>> -----------------------------
>> "Henry Jones" <he***@yada.com> wrote in message
>> news:OlZxzANDHHA.4228@TK2MSFTNGP03.phx.gbl...
>>> VB.NET Windows Forms VS 2005
>>>
>>> I would like to give the user the option of changing the background
>>> color of the textbox to anything they want.  Can someone provide code
>>> how to save the
>>> textbox1.BackColor to a string and then convert it back to a color that
>>> I can assign to the textbox?
>>>
>>> I have looked at colorconverter class which can inherit from the
>>> TypeConverter class and it's all too confusing.  I tried some examples
>>> and just can't get it.
>>>
>>> I tried something like this:
>>>
>>> Dim myColor As Color = Color.PaleVioletRed
>>>
>>>    ' Create the ColorConverter.
>>>    Dim converter As System.ComponentModel.TypeConverter = _
>>>       System.ComponentModel.TypeDescriptor.GetConverter(myColor)
>>>
>>>
>>> and it works if the color is already set, but what if I want the user to
>>> choose from the Color Dialog box?
>>>
>>> HELP please
>>>
>>
>>
>
>
Author
20 Nov 2006 8:08 PM
me
Henry Jones wrote:
Show quoteHide quote
> VB.NET Windows Forms VS 2005
>
> I would like to give the user the option of changing the background color of
> the textbox to anything they want.  Can someone provide code how to save the
> textbox1.BackColor to a string and then convert it back to a color that I
> can assign to the textbox?
>
> I have looked at colorconverter class which can inherit from the
> TypeConverter class and it's all too confusing.  I tried some examples and
> just can't get it.
>
> I tried something like this:
>
>  Dim myColor As Color = Color.PaleVioletRed
>
>     ' Create the ColorConverter.
>     Dim converter As System.ComponentModel.TypeConverter = _
>        System.ComponentModel.TypeDescriptor.GetConverter(myColor)
>
>
> and it works if the color is already set, but what if I want the user to
> choose from the Color Dialog box?
>
> HELP please
>
>
>
Use the common dialog for color full open style to select a color

for use of the color between runs, create registry entry for your
program under current user/software/programname/startup/textbox1color
etc...  or create your own ini file.

save all settings before exit... load all on startup


----== Posted via Newsfeeds.Com - Unlimited-Unrestricted-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =----
Author
21 Nov 2006 3:06 PM
Henry Jones
I have  a table with user options that is why I wanted to store the color
options as a string.
I thought if I converted the value to a string, it would be easy to convert
back.  But no, it's not.

Thanks,

Henry

Show quoteHide quote
"me" <gene1***@lisco.com> wrote in message
news:1164053375_21217@sp6iad.superfeed.net...
> Henry Jones wrote:
>> VB.NET Windows Forms VS 2005
>>
>> I would like to give the user the option of changing the background color
>> of the textbox to anything they want.  Can someone provide code how to
>> save the
>> textbox1.BackColor to a string and then convert it back to a color that I
>> can assign to the textbox?
>>
>> I have looked at colorconverter class which can inherit from the
>> TypeConverter class and it's all too confusing.  I tried some examples
>> and just can't get it.
>>
>> I tried something like this:
>>
>>  Dim myColor As Color = Color.PaleVioletRed
>>
>>     ' Create the ColorConverter.
>>     Dim converter As System.ComponentModel.TypeConverter = _
>>        System.ComponentModel.TypeDescriptor.GetConverter(myColor)
>>
>>
>> and it works if the color is already set, but what if I want the user to
>> choose from the Color Dialog box?
>>
>> HELP please
> Use the common dialog for color full open style to select a color
>
> for use of the color between runs, create registry entry for your program
> under current user/software/programname/startup/textbox1color etc...  or
> create your own ini file.
>
> save all settings before exit... load all on startup
>
>
> ----== Posted via Newsfeeds.Com - Unlimited-Unrestricted-Secure Usenet
> News==----
> http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+
> Newsgroups
> ----= East and West-Coast Server Farms - Total Privacy via Encryption
> =----
Author
21 Nov 2006 1:00 PM
guy
Why a string?
just keep it as a color
or if you must there is always Color.ToString
or more sensibly
color.FromARGB / Color.ToARGB convert colours To/From integers
and if you ***really*** need it as a string use the above to get the integer
and then convert that to a string (although I cannot see the point)

Guy

Show quoteHide quote
"Henry Jones" wrote:

> VB.NET Windows Forms VS 2005
>
> I would like to give the user the option of changing the background color of
> the textbox to anything they want.  Can someone provide code how to save the
> textbox1.BackColor to a string and then convert it back to a color that I
> can assign to the textbox?
>
> I have looked at colorconverter class which can inherit from the
> TypeConverter class and it's all too confusing.  I tried some examples and
> just can't get it.
>
> I tried something like this:
>
>  Dim myColor As Color = Color.PaleVioletRed
>
>     ' Create the ColorConverter.
>     Dim converter As System.ComponentModel.TypeConverter = _
>        System.ComponentModel.TypeDescriptor.GetConverter(myColor)
>
>
> and it works if the color is already set, but what if I want the user to
> choose from the Color Dialog box?
>
> HELP please
>
>
>
Author
21 Nov 2006 3:06 PM
Henry Jones
Thanks for the info, but how can I keep it as a color in a table?  I will
look up the Color options you suggested.

Henry

Show quoteHide quote
"guy" <g**@discussions.microsoft.com> wrote in message
news:15577415-6A1E-4CBD-AF1A-1E3190E6F31E@microsoft.com...
> Why a string?
> just keep it as a color
> or if you must there is always Color.ToString
> or more sensibly
> color.FromARGB / Color.ToARGB convert colours To/From integers
> and if you ***really*** need it as a string use the above to get the
> integer
> and then convert that to a string (although I cannot see the point)
>
> Guy
>
> "Henry Jones" wrote:
>
>> VB.NET Windows Forms VS 2005
>>
>> I would like to give the user the option of changing the background color
>> of
>> the textbox to anything they want.  Can someone provide code how to save
>> the
>> textbox1.BackColor to a string and then convert it back to a color that I
>> can assign to the textbox?
>>
>> I have looked at colorconverter class which can inherit from the
>> TypeConverter class and it's all too confusing.  I tried some examples
>> and
>> just can't get it.
>>
>> I tried something like this:
>>
>>  Dim myColor As Color = Color.PaleVioletRed
>>
>>     ' Create the ColorConverter.
>>     Dim converter As System.ComponentModel.TypeConverter = _
>>        System.ComponentModel.TypeDescriptor.GetConverter(myColor)
>>
>>
>> and it works if the color is already set, but what if I want the user to
>> choose from the Color Dialog box?
>>
>> HELP please
>>
>>
>>
Author
21 Nov 2006 6:25 PM
guy
convert it to an integer using FromARGB and ToARGB

hth

guy

Show quoteHide quote
"Henry Jones" wrote:

> Thanks for the info, but how can I keep it as a color in a table?  I will
> look up the Color options you suggested.
>
> Henry
>
> "guy" <g**@discussions.microsoft.com> wrote in message
> news:15577415-6A1E-4CBD-AF1A-1E3190E6F31E@microsoft.com...
> > Why a string?
> > just keep it as a color
> > or if you must there is always Color.ToString
> > or more sensibly
> > color.FromARGB / Color.ToARGB convert colours To/From integers
> > and if you ***really*** need it as a string use the above to get the
> > integer
> > and then convert that to a string (although I cannot see the point)
> >
> > Guy
> >
> > "Henry Jones" wrote:
> >
> >> VB.NET Windows Forms VS 2005
> >>
> >> I would like to give the user the option of changing the background color
> >> of
> >> the textbox to anything they want.  Can someone provide code how to save
> >> the
> >> textbox1.BackColor to a string and then convert it back to a color that I
> >> can assign to the textbox?
> >>
> >> I have looked at colorconverter class which can inherit from the
> >> TypeConverter class and it's all too confusing.  I tried some examples
> >> and
> >> just can't get it.
> >>
> >> I tried something like this:
> >>
> >>  Dim myColor As Color = Color.PaleVioletRed
> >>
> >>     ' Create the ColorConverter.
> >>     Dim converter As System.ComponentModel.TypeConverter = _
> >>        System.ComponentModel.TypeDescriptor.GetConverter(myColor)
> >>
> >>
> >> and it works if the color is already set, but what if I want the user to
> >> choose from the Color Dialog box?
> >>
> >> HELP please
> >>
> >>
> >>
>
>
>