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.
When picking or choosing a color from the color dialog box, the background color of the from will change as we have the code 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:
Full source code:
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; } } }