I am trying to assign the color value returned from ColorDialog
on one form to another form.
Form 1 consists of 2 buttons: 'Place Order' (creates a new form with bunch of controls) and 'Select Color' (allows you to change the color of Place Order form). So you can't have Place Order and Select Color open at the same time.
Therefore, I somehow must reference the BackColor
property of the Place Order form to form that has the two buttons so that ColorDialog.Color
can be assigned to the Place Order form.
Form1 Code:
private void SelectColor_Click(object sender, EventArgs e)
{
if (colorDialog1.ShowDialog() == DialogResult.OK)
{
string color = Convert.ToString(colorDialog1.Color);
MessageBox.Show(color);
this.BackColor = colorDialog1.Color; // BackColor is only accessible for this form
}
}
The way you are doing this, you will need to maintain a variable to hold the color. Do it like this:
then in the code where you launch your new form (Place order button) put this: