// Programmer: Janet Joy // Happy Birthday illustrates using menu, tool strip, status bar // and dialog boxes to select font, file and color. using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace happybirthday { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void mnuExit_Click(object sender, EventArgs e) { this.Close(); } private void mnuNew_Click(object sender, EventArgs e) { picHappy.Image = null; this.BackColor = Color.White; } private void timer1_Tick(object sender, EventArgs e) { statusTime.Text = System.DateTime.Now.ToString(); } private void mnuOpen_Click(object sender, EventArgs e) { // The filter determines which file types can be selected. openFileDialog1.Filter = "All Pictures|*.bmp;*.gif;*.png;*.jpg|JPG|*.jpg|Bitmaps|*.bmp|GIFS|*.gif|PNG|*.png"; this.openFileDialog1.ShowDialog(); // If the user selects "Cancel" filename will be "". if(openFileDialog1.FileName!="") { picHappy.Load(openFileDialog1.FileName); statusFile.Text = openFileDialog1.FileName; } } private void toolStripOpen_Click(object sender, EventArgs e) { mnuOpen_Click(sender, e); } private void mnuFont_Click(object sender, EventArgs e) { // Show the font dialog. fontDialog1.ShowDialog(); // If the user selects cancel, the font will be null. if (fontDialog1.Font != null) { // Change the label to the selected font. lblHappy.Font = fontDialog1.Font; } } private void toolStripFont_Click(object sender, EventArgs e) { mnuFont_Click(sender, e); } 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); } } }