Click here to Skip to main content
14,362,953 members
   

C#

 
AnswerRe: Using buttons on a form. Pin
OriginalGriff15-Sep-19 21:43
protectorOriginalGriff15-Sep-19 21:43 
AnswerRe: Using buttons on a form. Pin
GenJerDan15-Sep-19 21:55
memberGenJerDan15-Sep-19 21:55 
GeneralRe: Using buttons on a form. Pin
BillWoodruff16-Sep-19 5:32
mveBillWoodruff16-Sep-19 5:32 
AnswerRe: Using buttons on a form. Pin
BillWoodruff16-Sep-19 5:30
mveBillWoodruff16-Sep-19 5:30 
AnswerRe: Using buttons on a form. Pin
Brian_TheLion16-Sep-19 17:20
memberBrian_TheLion16-Sep-19 17:20 
GeneralRe: Using buttons on a form. Pin
BillWoodruff16-Sep-19 17:36
mveBillWoodruff16-Sep-19 17:36 
GeneralRe: Using buttons on a form. Pin
Brian_TheLion16-Sep-19 21:40
memberBrian_TheLion16-Sep-19 21:40 
AnswerRe: Using buttons on a form. Pin
BillWoodruff16-Sep-19 23:49
mveBillWoodruff16-Sep-19 23:49 
Here's how I would approach this:

flow-of-control: a GroupBox is shown with a current question; the user must click one of two radio-buttons to enable a Button that moves to the next question. Next questions are presented until the list of questions is enumerated.

0 a Button that will start the quiz 'btnShowQuiz: visible on the Main Form

1 a GroupBox 'grpbxQuiz: set not visible containing:
a TextBox 'tbxQuizQuestion

two RadioButtons 'rbtnYes 'rbtnNo : the 'CheckChanged for both these RadioButtons is set to 'rbtn_CheckedChanged

a Button 'btnNextQuestion
// used to reset RadioButton state
private bool ignoreRBCheckEvent = true;

private List<string> questions = new List<string>
{
    "who", "when", "where", "how"
};

// holds results
private Dictionary<int, bool> QA = new Dictionary<int, bool>();

// question counter
private int qcnt = 0;

// show the quiz
private void btnShowQuiz_Click(object sender, EventArgs e)
{
    QA.Clear();
    qcnt = 0;

    tbxQuizQuestion.Text = questions[0];

    btnNextQuestion.Enabled = false;

    rbtnYes.Enabled = true;
    rbtnYes.CheckedChanged += rbtn_CheckedChanged;

    rbtnNo.Enabled = true;
    rbtnNo.CheckedChanged += rbtn_CheckedChanged;

    ignoreRBCheckEvent = false;

    grpbxQuiz.Visible = true;

    // set the clip
    Cursor.Clip = grpbxQuiz.RectangleToScreen(grpbxQuiz.ClientRectangle);
}

private void BtnNextQuestion_Click(object sender, EventArgs e)
{
    ignoreRBCheckEvent = true;

    rbtnYes.Checked = false;
    rbtnNo.Checked = false;

    btnNextQuestion.Enabled = false;

    tbxQuizQuestion.Text = questions[qcnt];

    ignoreRBCheckEvent = false;
}

private void rbtn_CheckedChanged(object sender, EventArgs e)
{
    if (ignoreRBCheckEvent) return;

    QA.Add(qcnt++, rbtnYes.Checked);

    if (qcnt < questions.Count)
    {
        btnNextQuestion.Enabled = true;
    }
    else
    {
        // release the clip
        Cursor.Clip = Rectangle.Empty;
        grpbxQuiz.Visible = false;
        OnQuizFinished();

    }
}

// inspect the results
public void OnQuizFinished()
{
    foreach (var kvp in QA)
    {
        Console.WriteLine($"({kvp.Key}) \"{questions[kvp.Key]}\" | {kvp.Value}");
    }
}
note the use of clipping the Cursor to restrict mouse input to the GroupBox.
«One day it will have to be officially admitted that what we have christened reality is an even greater illusion than the world of dreams.» Salvador Dali


modified 17-Sep-19 5:10am.

GeneralRe: Using buttons on a form. Pin
Brian_TheLion17-Sep-19 21:03
memberBrian_TheLion17-Sep-19 21:03 
QuestionFile format not proper for excel mail attachment in c# Pin
Member 1225501213-Sep-19 9:33
memberMember 1225501213-Sep-19 9:33 
AnswerRe: File format not proper for excel mail attachment in c# Pin
MadMyche13-Sep-19 12:59
mveMadMyche13-Sep-19 12:59 
QuestionHow to get the Websocketdata from server? Pin
Member 1457084312-Sep-19 7:46
memberMember 1457084312-Sep-19 7:46 
AnswerRe: How to get the Websocketdata from server? Pin
Richard MacCutchan12-Sep-19 7:49
protectorRichard MacCutchan12-Sep-19 7:49 
GeneralRe: How to get the Websocketdata from server? Pin
Member 1457084312-Sep-19 8:14
memberMember 1457084312-Sep-19 8:14 
GeneralRe: How to get the Websocketdata from server? Pin
Richard MacCutchan12-Sep-19 12:15
protectorRichard MacCutchan12-Sep-19 12:15 
AnswerRe: How to get the Websocketdata from server? Pin
ZurdoDev12-Sep-19 10:48
professionalZurdoDev12-Sep-19 10:48 
AnswerRe: How to get the Websocketdata from server? Pin
Gerry Schmitz12-Sep-19 21:36
mveGerry Schmitz12-Sep-19 21:36 
AnswerRe: How to get the Websocketdata from server? Pin
OriginalGriff13-Sep-19 1:25
protectorOriginalGriff13-Sep-19 1:25 
QuestionWPF or Winforms Pin
N.Subramanian12-Sep-19 1:12
memberN.Subramanian12-Sep-19 1:12 
AnswerRe: WPF or Winforms Pin
OriginalGriff12-Sep-19 1:15
protectorOriginalGriff12-Sep-19 1:15 
AnswerRe: WPF or Winforms Pin
Richard MacCutchan12-Sep-19 4:18
protectorRichard MacCutchan12-Sep-19 4:18 
AnswerRe: WPF or Winforms Pin
Gerry Schmitz12-Sep-19 7:13
mveGerry Schmitz12-Sep-19 7:13 
GeneralRe: WPF or Winforms Pin
Eddy Vluggen13-Sep-19 0:21
mveEddy Vluggen13-Sep-19 0:21 
GeneralRe: WPF or Winforms Pin
Gerry Schmitz13-Sep-19 12:15
mveGerry Schmitz13-Sep-19 12:15 
GeneralRe: WPF or Winforms Pin
Eddy Vluggen13-Sep-19 13:19
mveEddy Vluggen13-Sep-19 13:19 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.