Program states that in one form if we want to place one button, while clicking on the button next form is appear with change color and having a display button like change color in a new window button, if we click new window button we will take color dialog box along with button which looks like button (…) along with the textbox. If we click on (…)button color dialog box is appear and if we choose color on that dialog box the back color of the textbox will be filled like that.
Open new project and create a Form1 with one button having text property click
to change color as shown below.
Place a code on the double click on the button event.
public partial class color : Form
Boolean check = false;//declare check for conditions
private void BtnColour_Click(object sender, EventArgs e)
if (check == false)//checking conditions if check is false
//then executes this statement.
this.BackColor = Color.Red;//color of the form is red.
BtnColour.Text = "new window";//resetting button text
check = true;
Form1 fm = new Form1();//create object of the form as fm
Next create another page with the help of add existing item,as shown below:
As soon as we click on the button(…)we can see a colour dialog box as shown
As soon as we select color in the colordialogbox it will come in the textbox.
Now place a piece of code on the button (…) as below.
private void btncolor_Click(object sender, EventArgs e)
colorDialog1.ShowDialog();//dialogbox will appear.
textBox1.BackColor = colorDialog1.Color;//in textbox1backcolour filled with the help of colour dialog box as shown in above figure.
Similarly for the second color dialog button (…)
private void button1_Click(object sender, EventArgs e)
txtBrowser2.BackColor = colorDialog2.Color;
The output will be appear like
As soon as we click color with the help of color dialog box we will see particular color in the textbox. As shown below in the snapshot.