Change Background Color using ColorDialog in C#
Submitted by donbermoy on Saturday, June 7, 2014 - 10:00.
Today in C#, I will teach you how to create a program that changes background color using ColorDialog in C#.
Now, let's start this Color Dialog tutorial!
1. Let's start with creating a Windows Form Application for this tutorial by following the following steps in Microsoft Visual Studio: Go to File, click New Project, and choose Windows Application.
2. Next, add only one Button named Button1 and labeled it as "Change Background Color". Next, put a ColorDialog as a dialog box control in your toolbox.
3. Add ColorDialog from the toolbox:
4. Now put add this code for your code module. This code is for Button1_Click and this will trigger to open the colordialog and after choosing the color, it will be the color of your background in the Form.
When picking or choosing a color from the color dialog box, the background color of the from will change as we have the code
Full source code:
Press F5 to run the program.
Best Regards,
Engr. Lyndon Bermoy
IT Instructor/System Developer/Android Developer/Freelance Programmer
If you have some queries, feel free to contact the number or e-mail below.
Mobile: 09488225971
Landline: 826-9296
E-mail:[email protected]
Add and Follow me on Facebook: https://www.facebook.com/donzzsky
Visit and like my page on Facebook at: https://www.facebook.com/BermzISware


- public void Button1_Click(System.Object sender, System.EventArgs e)
- {
- ColorDialog1.ShowDialog();
- this.BackColor = ColorDialog1.Color;
- }
ColorDialog1.ShowDialog()
- is our syntax for opening the color dialog box. It will look like this one when you click the button.

Me.BackColor = ColorDialog1.Color
. This means that the value of the color you choose in you colordialog will be equal to the background color of your form.
Now, click the Ok from your ColorDialog. It will change the back color of your form like this:

- using System.Diagnostics;
- using System;
- using System.Windows.Forms;
- using System.Collections;
- using System.Drawing;
- using Microsoft.VisualBasic;
- using System.Data;
- using System.Collections.Generic;
- namespace ChangeBackground_Color
- {
- public partial class Form1
- {
- public Form1()
- {
- InitializeComponent();
- }
- public void Button1_Click(System.Object sender, System.EventArgs e)
- {
- ColorDialog1.ShowDialog();
- this.BackColor = ColorDialog1.Color;
- }
- }
- }
Add new comment
- 845 views