Hi all,

I am developing a windows application.

I have 3 forms:

I want to change the backcolor of all the 3 forms to the color selected by the user.

I have used the following code I am able to change the backcolor but When I exit the application and restart it I am not able to get the color that user has set. I am getting the default colour only.

Is it possible to retain the colour selected by the user and use it as backcolor when the user restarts the application.

CODE

In Form1

ColorDialog c1 = new ColorDialog();
        public static System.Drawing.Color bkc;
        private void button1_Click(object sender, EventArgs e)
        {

            DialogResult res = c1.ShowDialog();
            if (res == DialogResult.OK)
            {
                bkc = c1.Color;
                this.BackColor = bkc;

               
                MessageBox.Show(Convert.ToString(bkc));
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            Form2 obj1 = new Form2();
            obj1.BackColor = bkc;
            obj1.Show();
        }

In Form 2
CODE

private void button2_Click(object sender, EventArgs e)
        {
            Form3 obj1 = new Form3();
            obj1.Show();
        }

        private void Form2_Load(object sender, EventArgs e)
        {
            this.BackColor = Form1.bkc;
                    
        }

In Form3
CODE

private void button2_Click(object sender, EventArgs e)
        {
            Form1 obj1 = new Form1();
            obj1.Show();
        }

        private void Form3_Load(object sender, EventArgs e)
        {
            //Form1 obj2 = new Form1();
            this.BackColor = Form1.bkc;
        }

In the color dialog box I am selecting a color and pressing Ok button the color is also changed but when I restart the application I dont get the colour which I set using the Color Dialog.I want to retain this setting so that the user can get the desired color without resetting it each time the application is executed.

The above code does not generate any error.

can anybody help me out in performing this task?

Thanks in advance!

1) Create a new setting in Settings.Settings file in properties and set its type as System.Drawing.Color.
2) Where ever in your code you choose a colour from the user, set the property and save it.

Properties.Settings.Default.colour = c1.Color; //set the selected colour //to the setting colour which you had created.
Properties.Settings.Default.Save();

3) When Use this setting to set the colour where you require.

1) Create a new setting in Settings.Settings file in properties and set its type as System.Drawing.Color.
2) Where ever in your code you choose a colour from the user, set the property and save it.

Properties.Settings.Default.colour = c1.Color; //set the selected colour //to the setting colour which you had created.
Properties.Settings.Default.Save();

3) When Use this setting to set the colour where you require.

Thanks for your reply.

I have done the steps given by you.

When I execute the application, select the color and press OK button I am getting the RunTime Exception:

ConfigurationErrorsException Was UnHandled.
Configuration system failed to initialize

What should I do now?

Can you tell me where you have added the lines.

The solution provided in the previous thread of yours was a better one, i have modified it to make the colours permanent.
Hope this solves your problem.

Can you tell me where you have added the lines.

I have added the line in the button1_click() event after assigning the color to the variable bkc.

Here is another way using the System.Configuration namespace

Here is another way using the System.Configuration namespace

Thanks for attaching the file. But I am not able to open the .sln or C# Project file I am getting the error as Forms missing.

Can you just post the relevant coding used to perform this task?

Thanks in advance!

You are getting a designer error, not a compiler error. I posted that this would happen in the last thread.

Open the solution, close all tabs in the IDE, rebuild the solution (ignore the errors), then after it compiles you will be able to open the forms. You can't open the forms until you rebuild the project.

You are getting a designer error, not a compiler error. I posted that this would happen in the last thread.

Open the solution, close all tabs in the IDE, rebuild the solution (ignore the errors), then after it compiles you will be able to open the forms. You can't open the forms until you rebuild the project.

Thanks for your reply.

When I right click Solution Explorer and select Build I am getting the following error:

Error 1 Unable to create a manifest resource name for "Form1.resx". Could not find file 'C:\Documents and Settings\Admin\Local Settings\Temp\Rar$DI07.766\Form1.cs'. daniweb.frmcolor

Error 2 Unable to create a manifest resource name for "Form2.resx". Could not find file 'C:\Documents and Settings\Admin\Local Settings\Temp\Rar$DI07.766\Form2.cs'. daniweb.frmcolor

Error 3 Unable to create a manifest resource name for "Form3.resx". Could not find file 'C:\Documents and Settings\Admin\Local Settings\Temp\Rar$DI07.766\Form3.cs'. daniweb.frmcolor

What should I do to overcome this problem?

Please help me out!

Zip your project and upload it. Something looks wrong.

Wait a minute.... It looks like you double clicked the .ZIP file and opened the solution with VS. Try unzipping the archive to a directory and opening it that way.

Wait a minute.... It looks like you double clicked the .ZIP file and opened the solution with VS. Try unzipping the archive to a directory and opening it that way.

Thanks for your prompt reply!

I am able to open the file now and your code performs the task in the same way as I desired.

Thanks for all your help.

Since I am a beginner I dont understand the code written in the app.config can you explain me the coding in the app.config file if possible?

Anyways Thanks a lot for all your help!

The code for app.config is generated by the IDE. Double click on the file and add properties via the user interface.

The code for app.config is generated by the IDE. Double click on the file and add properties via the user interface.

Thank you!

Thanks a lot!

The code for app.config is generated by the IDE. Double click on the file and add properties via the user interface.

Can you please tell What is the Use of Using block?

using (ColorDialog cd = new ColorDialog())

Start new threads to ask these questions as they are outside the scope of your original post.

a using() block calls IDisposable.Dispose() on objects inside the using(..here..).

Please read this MSDN article on using():
http://msdn.microsoft.com/en-us/library/yh598w02(VS.80).aspx

Start new threads to ask these questions as they are outside the scope of your original post.

a using() block calls IDisposable.Dispose() on objects inside the using(..here..).

Please read this MSDN article on using():
http://msdn.microsoft.com/en-us/library/yh598w02(VS.80).aspx

Thanks for reply!

Sorry to ask you so many questions

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.