I have a colordialog box that I save the color last chosen using property bindings and My.Settings. My issue is that if they select and/or add a custom color, it doesnt remember the color added when I reload the program.
Printable View
I have a colordialog box that I save the color last chosen using property bindings and My.Settings. My issue is that if they select and/or add a custom color, it doesnt remember the color added when I reload the program.
Are you reading/loading the custom color from your saved settings?
You're either not loading the Color or not saving it because I just tested it and it worked perfectly. I started a new project, created a setting of type Color named "Colour", added a Panel and a Button to the form and then added this code:Everything worked exactly as it should, whether I chose a standard or custom colour.vb.net Code:
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Me.Panel1.BackColor = My.Settings.Colour End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Using dialogue As New ColorDialog If dialogue.ShowDialog() = Windows.Forms.DialogResult.OK Then My.Settings.Colour = dialogue.Color Me.Panel1.BackColor = dialogue.Color End If End Using End Sub
I think you misunderstood my issue. The contol remembers the color. However the color dialog box does not remember the custom color. So if the user clicks on the color dialog box, his custom color cannot be selected by default because it is not there.
Ah, I see. You are quite correct that the ColorDialog doesn't "remember" the custom colours. If you want that functionality then it's up to you to provide it. The ColorDialog has a CustomColors property that you can set before it's displayed and get after it's dismissed. If you want to save the custom colours and display them to the user in future then it's up to you to use that property and persist the colour values between sessions.