Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / VB.NET / November 2006

Tip: Looking for answers? Try searching our database.

Saving the Color value into a string

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Henry Jones - 20 Nov 2006 18:17 GMT
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
RobinS - 20 Nov 2006 19:26 GMT
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.
-----------------------------
> VB.NET Windows Forms VS 2005
>
[quoted text clipped - 20 lines]
>
> HELP please
Henry Jones - 21 Nov 2006 15:04 GMT
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

> Why do you want to convert it to a string?
>
[quoted text clipped - 28 lines]
>>
>> HELP please
RobinS - 21 Nov 2006 17:51 GMT
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.

>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
[quoted text clipped - 36 lines]
>>>
>>> HELP please
me - 20 Nov 2006 20:08 GMT
> VB.NET Windows Forms VS 2005
>
[quoted text clipped - 19 lines]
>
> 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
Henry Jones - 21 Nov 2006 15:06 GMT
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

>> VB.NET Windows Forms VS 2005
>>
[quoted text clipped - 34 lines]
> ----= East and West-Coast Server Farms - Total Privacy via Encryption
> =----
guy - 21 Nov 2006 13:00 GMT
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

> VB.NET Windows Forms VS 2005
>
[quoted text clipped - 19 lines]
>
> HELP please
Henry Jones - 21 Nov 2006 15:06 GMT
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

> Why a string?
> just keep it as a color
[quoted text clipped - 33 lines]
>>
>> HELP please
guy - 21 Nov 2006 18:25 GMT
convert it to an integer using FromARGB and ToARGB

hth

guy

> 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.
[quoted text clipped - 38 lines]
> >>
> >> HELP please

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.