Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

C# RadioButtons

cowgirl1996cowgirl1996 United StatesPosts: 6Member

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.

Here 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.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"; 
    } 
} 

}

I don't know what I'm doing wrong!!!!

Comments

  • seancampbellseancampbell Pennsylvania, USAPosts: 684Member ✭✭✭

    This looks like school work. I could easily just do this for you, but here is some explanation to help you understand programming. I hope I am not mistaken, I do not wish to offend, but I like learning and teaching so this helps me too.

    Create a Form that contains a guessing game with five RadioButtons numbered 1 through 5.

    --First you need to set a few things up when the program runs and the form loads up.

    --Define a variable outside of your function/sub/(private void) calls

    --Look for an event called Load. There should be 2 drop downs above your code, in the left one select the top level object, called form or something like that. Then in the right hand drop down, you want to select the Load even (Not LoadComplete). Once you click it, it should create a code block for you to type code into.

    --In the Load function, you will Create a Random integer between 1 and 5

    ** Randomly choose one of the RadioButtons as the winning button. **(we just did that, now we have a variable with a random number which indicates which button it is)

    **When the user clicks a RadioButton, display a message indicating whether the user is correct. **

    --In each of the Radio Button click/selected events that you already have code in, you want to check against the number you just stored outside of the functions. Variables declared outside of functions stay around for you to compare with later.

    --So in radio button 1, it would be something like

    if(iWinningNumber == 1) { //tell them they won here } else { //tell them to eat cheese here }

    **Add a Label to the Form that provides a hint. **

    --I think you already have a label on your form, but you want one of those somewhere.

    **When the user's mouse hovers over the label, notify the user of one RadioButton that is incorrect. **

    --Don't let these bitches fool you, MouseHover is evil. You want to use MouseIn and MouseOut or MouseOver or something like that.

    --Find the mouseOver function the way you find the Form load function (explained above)

    --Inside of your Mouse In function, you have to make a random number but you also have to make sure that random number is not equal to the Winning number. To do this kind of thing, you have to make a loop that only ends when a random number is created that is not equal to Winning number (80% of the time, it will exit on the first try). The best way to do this in my opinion is with a While or Do loop.

    while (true) //this is infinite, you need to break out of this loop { // statements

    //Generate number 1-5 //If number != WinningNumber Then // break will exit the first open loop it finds above it ( // so if you have a loop in a loop, it wouldn't break out of both) // break; //end if

    }

    **After the user makes a selection, disable all the RadioButtons. **

    --In ever single radiobutton check, you will make code that shuts each radiobutton off with RadioButton.enabled = false;

    Title the project GuessANumber.

    --Eff the man, name it StealCarRadioButtons

    I hope this helps you complete your work. If it does, show me some love on my soundcloud.com/firesickle account

  • cowgirl1996cowgirl1996 United StatesPosts: 6Member

    Thank you!!! I'd much rather understand than just have the answers!!!! Will be much more beneficial to me in the long run!

Sign In or Register to comment.