AllTheTimeWorld.com

csharp dialogsAdd the Color dialog to select a background color for the Happy Birthday App

Add the Color dialog to select a background color for the Happy Birthday App

Includes a different way to determine if the user clicked cancel

Add the Color dialog to select a background color for the Happy Birthday App

Includes a different way to determine if the user clicked cancel


Text of video

Write the code as shown below:

private void mnuColor_Click(object sender, EventArgs e)
{
  // This is a different way to determine if the user clicked cancel.
  // Show the color dialog and store result (Ok or Cancel).
  DialogResult result = colorDialog1.ShowDialog();
  // See if user pressed ok.
  if (result == DialogResult.OK)
  {
     // Set form background to the selected color.
     this.BackColor = colorDialog1.Color;
  }
}

private void toolStripColor_Click(object sender, EventArgs e)
{
   mnuColor_Click(sender, e);
}

Experiment: After the font changes, or the greeting changes, or the size of the form changes, center the greeting.
After the picture changes, or when the form changes size, center the picture.