In: Computer Science
Create a Windows application in C# that can be used to change the form color. Your form background color should initially be blue. Provide at least two buttons with two different color choices and a Reset option. Change the font style and size on buttons. Align the buttons so that they are in the center of the form. The color choice buttons should be the same size. Add event handlers for the buttons so that when the user click the button, the form changes the color, and the message box is displayed alerting the user to what color the form is. Be sure to name any controls used in the program statements prior to registering your event. Change the default title bar text.
Greetings!!!!!!!!!!!!!!!!!
Please find detail of Window application in c#. It includes following deliverables as part of question.
1) Screen shot of the solution in design mode.
2) ChangeFormColor.cs code in C#
3) ChangeFormColor.Designer.cs code in c#
4) Screen shots of sample run
i) Initially Blue Color of form as back color
ii) Red Color button clicked to change back color to red with message box of current color.
iii) Green Color button clicked to change back color to green with message box of current color.
iv) Reset Color button clicked to change back color to default (blue) with message box of current color.
1) Screen shot of the solution in design mode.
2) ChangeFormColor.cs code in C#
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 ChangeColorOfWindowForm
{
public partial class ChangeFormColor : Form
{
public ChangeFormColor()
{
InitializeComponent();
}
private void ChangeFormColor_Load(object sender, EventArgs e)
{
}
private void btnRedColor_Click(object sender, EventArgs e)
{
this.BackColor = Color.Red;
MessageBox.Show("Back Color of form is changed to red.");
}
private void btnGreenColor_Click(object sender, EventArgs e)
{
this.BackColor = Color.Green;
MessageBox.Show("Back Color of form is changed to green.");
}
private void btnResetColor_Click(object sender, EventArgs e)
{
this.BackColor = Color.Blue;
MessageBox.Show("Back Color of form is reset to blue.");
}
}
}
3) ChangeFormColor.Designer.cs code in c#
namespace ChangeColorOfWindowForm
{
partial class ChangeFormColor
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.btnRedColor = new System.Windows.Forms.Button();
this.btnGreenColor = new System.Windows.Forms.Button();
this.btnResetColor = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// btnRedColor
//
this.btnRedColor.Location = new System.Drawing.Point(259, 193);
this.btnRedColor.Name = "btnRedColor";
this.btnRedColor.Size = new System.Drawing.Size(75, 23);
this.btnRedColor.TabIndex = 0;
this.btnRedColor.Text = "Red Color";
this.btnRedColor.UseVisualStyleBackColor = true;
this.btnRedColor.Click += new System.EventHandler(this.btnRedColor_Click);
//
// btnGreenColor
//
this.btnGreenColor.Location = new System.Drawing.Point(386, 193);
this.btnGreenColor.Name = "btnGreenColor";
this.btnGreenColor.Size = new System.Drawing.Size(75, 23);
this.btnGreenColor.TabIndex = 1;
this.btnGreenColor.Text = "Green Color";
this.btnGreenColor.UseVisualStyleBackColor = true;
this.btnGreenColor.Click += new System.EventHandler(this.btnGreenColor_Click);
//
// btnResetColor
//
this.btnResetColor.Location = new System.Drawing.Point(499, 193);
this.btnResetColor.Name = "btnResetColor";
this.btnResetColor.Size = new System.Drawing.Size(75, 23);
this.btnResetColor.TabIndex = 2;
this.btnResetColor.Text = "Reset Color";
this.btnResetColor.UseVisualStyleBackColor = true;
this.btnResetColor.Click += new System.EventHandler(this.btnResetColor_Click);
//
// ChangeFormColor
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.BackColor = System.Drawing.Color.Blue;
this.ClientSize = new System.Drawing.Size(800, 450);
this.Controls.Add(this.btnResetColor);
this.Controls.Add(this.btnGreenColor);
this.Controls.Add(this.btnRedColor);
this.Name = "ChangeFormColor";
this.Text = "Change Back Color of Form";
this.Load += new System.EventHandler(this.ChangeFormColor_Load);
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.Button btnRedColor;
private System.Windows.Forms.Button btnGreenColor;
private System.Windows.Forms.Button btnResetColor;
}
}
4) Screen shots of sample run
i) Initially Blue Color of form as back color
ii) Red Color button clicked to change back color to red with message box of current color.
iii) Green Color button clicked to change back color to green with message box of current color.
iv) Reset Color button clicked to change back color to default (blue) with message box of current color.
Thank You