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.
publicpartialclasscolor : Form
{
Boolean check = false;//declare check for conditions
public color()
{
InitializeComponent();
}
privatevoid 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;
}
else
{
Form1 fm = newForm1();//create object of the form as fm
fm.ShowDialog();
}
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
below.
FIG 1
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.
privatevoid 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 (…)
privatevoid button1_Click(object sender, EventArgs e)
{
colorDialog2.ShowDialog();
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.
Anonymous User
21-Feb-2019Thanks for the help.
Sushant Mishra
14-Jul-2017It was really helpful to read this post.