I am using Microsoft Visual Studio and writing in C# This is my assignment: Crea
ID: 3673248 • Letter: I
Question
I am using Microsoft Visual Studio and writing in C#
This is my assignment: 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.
This is what I have so far:
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 GuessANumber
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
radioButton1.Checked = true;
}
private void button1_Click(object sender, EventArgs e)
{
if (radioButton4.Checked == true)
{
MessageBox.Show("You are winner!! ");
return;
}
else
{
MessageBox.Show("You have selected incorrrect options !! ");
return;
}
}
private void label1_MouseHover(object sender, EventArgs e)
{
label1.Font = new Font(label1.Font.Name, label1.Font.SizeInPoints, FontStyle.Underline);
label1.Text = "RadioButton that is incorrect.";
radioButton2.Checked = true;
}
}
}
My issue is that my radio buttons and label don't show up when I try to run the program, the form is blank so I can't even see if the rest is working as expected. Help!
Explanation / Answer
Buttons, Labe;ls in C# :
Windows Forms controls are reusable components that encapsulate user interface functionality and are used in client side Windows applications. A button is a control, which is an interactive component that enables users to communicate with an application. The Button class inherits directly from the ButtonBase class. A Button can be clicked by using the mouse, ENTER key, or SPACEBAR if the button has focus.
Labels are one of the most frequently used C# control. We can use the Label control to display text in a set location on the page. Label controls can also be used to add descriptive text to a Form to provide the user with helpful information. The Label class is defined in the System.Windows.Forms namespace.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void HINT_MouseHover(object sender, EventArgs e)
{
HoverLocationLabel.Text = "it's an even number";
}
private void radioButton1_CheckedChanged(object sender, EventArgs e)
{
if(Button1CheckBox.Checked)
radioButton1.Text = "incorrect";
}
private void radioButton2_CheckedChanged(object sender, EventArgs e)
{
if (Button2CheckBox.Checked)
radioButton2.Text = "incorrect";
}
private void radioButton3_CheckedChanged(object sender, EventArgs e)
{
if (Button3CheckBox.Checked)
radioButton3.Text = "incorrect";
}
private void radioButton4_CheckedChanged(object sender, EventArgs e)
{
if (Button4CheckBox.Checked)
radioButton4.Text = "incorrect";
}
private void radioButton5_CheckedChanged(object sender, EventArgs e)
{
if (Button5CheckBox.Checked)
radioButton5.Text = "incorrect";
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.