Setting a Color Value

SEF

Member
Joined
Feb 2, 2007
Messages
9
Programming Experience
Beginner
Hi Folks,

All im trying to do is change the back color of a label to the color chosen from a color dialog, i have the label changing color, but i want it to store the color until the user decides to change again, at present when i reload the form the color defaults to its original value. this might be a simple question but im new to vb.net and need all the help i can get.

Here is what i have so far:




Public
Class Coloroptions

PrivateSub changeColorButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles changecolorbutton.Click

If ColorDialog1.ShowDialog() = DialogResult.OK Then
lblCustomer.BackColor = ColorDialog1.Color

EndIf
EndSub

PublicProperty FavoriteColor() As Color

Get
Return colorDialog1.Color
EndGet

Set(ByVal Value As Color)
lblCustomer.BackColor = Value
ColorDialog1.Color = Value
EndSet

EndProperty

EndClass



Thanks for the help
 
Use Property Binding and Project Settings for this. First create a new setting of type Color in Project Settings, for instance name it "labelbackcolor". Then select the label and in its properties browse "(ApplicationSettings)(PropertyBinding)" where you find the controls BackColor property and map it to your "labelbackcolor" setting.

When you change this labels backcolor property value (as using the ColorDialog you do) the value is automatically stored in the given setting and restored when application restarts.
 
Hi thanks for the reply,

Ok set a new settings type 'labelbackcolor' to color, then bound the new setting to the backcolor of the label, but still no joy, i select the color in the dialog, the label changes color, but when i exit and go back in the value is still at default.

maybe i'm doing something wrong, appreciate any further help with this matter.

many thanks
 
I attach the screenshots of Settings screen and Label Properties, see if it look the same. The code I used same as yours, changing the labels backcolor property. It also works the same if you instead set the my.settings.labelbackcolor. When I restart application the color chosen in dialog is preserved, it works and nothing else done.

settings.jpg

property.jpg
 
Got all the same settings as you, but cant get it to work,could you post the code that you used to get it working.

many thanks
:D
 
Noticed something, when i update the label back color, with the my.settings.labelbackcolor the label does not change color, i have something wrong, but just cant see it!
 
Back
Top