Using C#, Create a Form that contains a guessing game with five RadioButtons num
ID: 3874875 • Letter: U
Question
Using C#, Create a Form that contains a guessing game with five RadioButtons numbered 1 through 5. Randomly choose one of the RadioButtons as the winning button. When the user clicks a RadioButton, display a message indicating whether the user is correct. Add a Label to the Form that provides a hint. When the user's mouse hovers over the label, notify the user of one RadioButton that is incorrect. After the user makes a selection, disable all the RadioButtons. Title the project GuessANumber. Compile and run your program until it works and the output looks nice. Add the necessary documentation as described in Course Documents, and then attach your .cs file to this assignment. Create a zip file of you project directory and attach it to this assignment. Please walk me through every step of setting up the buttons as well as this confuses me.
Explanation / Answer
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
namespace WindowsApplication1
{
/// <summary>
/// Summary description for Form1.
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.RadioButton radioButton2;
private System.Windows.Forms.RadioButton radioButton1;
private System.Windows.Forms.RadioButton radioButton3;
private System.Windows.Forms.RadioButton radioButton4;
private System.Windows.Forms.RadioButton radioButton5;
private System.Windows.Forms.TextBox textBox1;
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;
public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
//
// TODO: Add any constructor code after InitializeComponent call
//
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (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.radioButton2 = new System.Windows.Forms.RadioButton();
this.radioButton1 = new System.Windows.Forms.RadioButton();
this.radioButton3 = new System.Windows.Forms.RadioButton();
this.radioButton4 = new System.Windows.Forms.RadioButton();
this.radioButton5 = new System.Windows.Forms.RadioButton();
this.textBox1 = new System.Windows.Forms.TextBox();
this.SuspendLayout();
//
// radioButton2
//
this.radioButton2.Location = new System.Drawing.Point(128, 112);
this.radioButton2.Name = "radioButton2";
this.radioButton2.TabIndex = 1;
this.radioButton2.Text = "2";
this.radioButton2.CheckedChanged += new System.EventHandler(this.radioButton2_CheckedChanged);
//
// radioButton1
//
this.radioButton1.Cursor = System.Windows.Forms.Cursors.Default;
this.radioButton1.Location = new System.Drawing.Point(16, 112);
this.radioButton1.Name = "radioButton1";
this.radioButton1.TabIndex = 2;
this.radioButton1.Text = "1";
this.radioButton1.CheckedChanged += new System.EventHandler(this.radioButton1_CheckedChanged);
//
// radioButton3
//
this.radioButton3.Location = new System.Drawing.Point(240, 112);
this.radioButton3.Name = "radioButton3";
this.radioButton3.TabIndex = 3;
this.radioButton3.Text = "3";
this.radioButton3.CheckedChanged += new System.EventHandler(this.radioButton3_CheckedChanged);
//
// radioButton4
//
this.radioButton4.Location = new System.Drawing.Point(344, 112);
this.radioButton4.Name = "radioButton4";
this.radioButton4.TabIndex = 4;
this.radioButton4.Text = "4";
this.radioButton4.CheckedChanged += new System.EventHandler(this.radioButton4_CheckedChanged);
//
// radioButton5
//
this.radioButton5.Location = new System.Drawing.Point(448, 112);
this.radioButton5.Name = "radioButton5";
this.radioButton5.TabIndex = 5;
this.radioButton5.Text = "5";
this.radioButton5.CheckedChanged += new System.EventHandler(this.radioButton5_CheckedChanged);
//
// textBox1
//
this.textBox1.Location = new System.Drawing.Point(176, 176);
this.textBox1.Name = "textBox1";
this.textBox1.TabIndex = 7;
this.textBox1.Text = "MSG";
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(680, 404);
this.Controls.Add(this.textBox1);
this.Controls.Add(this.radioButton5);
this.Controls.Add(this.radioButton4);
this.Controls.Add(this.radioButton3);
this.Controls.Add(this.radioButton1);
this.Controls.Add(this.radioButton2);
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayout(false);
}
#endregion
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
private void radioButton1_CheckedChanged(object sender, System.EventArgs e)
{
try
{
Random RandomClass = new Random();
int randomNumber;
randomNumber = RandomClass.Next(1, 5);
if(randomNumber==1)
text
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.