Click here to Skip to main content
15,879,095 members
Home / Discussions / C#
   

C#

 
AnswerRe: Using buttons on a form. Pin
OriginalGriff15-Sep-19 20:43
mveOriginalGriff15-Sep-19 20:43 
AnswerRe: Using buttons on a form. Pin
GenJerDan15-Sep-19 20:55
GenJerDan15-Sep-19 20:55 
GeneralRe: Using buttons on a form. Pin
BillWoodruff16-Sep-19 4:32
professionalBillWoodruff16-Sep-19 4:32 
AnswerRe: Using buttons on a form. Pin
BillWoodruff16-Sep-19 4:30
professionalBillWoodruff16-Sep-19 4:30 
AnswerRe: Using buttons on a form. Pin
Brian_TheLion16-Sep-19 16:20
Brian_TheLion16-Sep-19 16:20 
GeneralRe: Using buttons on a form. Pin
BillWoodruff16-Sep-19 16:36
professionalBillWoodruff16-Sep-19 16:36 
GeneralRe: Using buttons on a form. Pin
Brian_TheLion16-Sep-19 20:40
Brian_TheLion16-Sep-19 20:40 
AnswerRe: Using buttons on a form. Pin
BillWoodruff16-Sep-19 22:49
professionalBillWoodruff16-Sep-19 22: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 20:03
Brian_TheLion17-Sep-19 20:03 
QuestionFile format not proper for excel mail attachment in c# Pin
Member 1225501213-Sep-19 8:33
Member 1225501213-Sep-19 8:33 
AnswerRe: File format not proper for excel mail attachment in c# Pin
MadMyche13-Sep-19 11:59
professionalMadMyche13-Sep-19 11:59 
QuestionHow to get the Websocketdata from server? Pin
Member 1457084312-Sep-19 6:46
Member 1457084312-Sep-19 6:46 
AnswerRe: How to get the Websocketdata from server? Pin
Richard MacCutchan12-Sep-19 6:49
mveRichard MacCutchan12-Sep-19 6:49 
GeneralRe: How to get the Websocketdata from server? Pin
Member 1457084312-Sep-19 7:14
Member 1457084312-Sep-19 7:14 
GeneralRe: How to get the Websocketdata from server? Pin
Richard MacCutchan12-Sep-19 11:15
mveRichard MacCutchan12-Sep-19 11:15 
AnswerRe: How to get the Websocketdata from server? Pin
ZurdoDev12-Sep-19 9:48
professionalZurdoDev12-Sep-19 9:48 
AnswerRe: How to get the Websocketdata from server? Pin
Gerry Schmitz12-Sep-19 20:36
mveGerry Schmitz12-Sep-19 20:36 
AnswerRe: How to get the Websocketdata from server? Pin
OriginalGriff13-Sep-19 0:25
mveOriginalGriff13-Sep-19 0:25 
QuestionWPF or Winforms Pin
N.Subramanian12-Sep-19 0:12
N.Subramanian12-Sep-19 0:12 
AnswerRe: WPF or Winforms Pin
OriginalGriff12-Sep-19 0:15
mveOriginalGriff12-Sep-19 0:15 
AnswerRe: WPF or Winforms Pin
Richard MacCutchan12-Sep-19 3:18
mveRichard MacCutchan12-Sep-19 3:18 
AnswerRe: WPF or Winforms Pin
Gerry Schmitz12-Sep-19 6:13
mveGerry Schmitz12-Sep-19 6:13 
GeneralRe: WPF or Winforms Pin
Eddy Vluggen12-Sep-19 23:21
professionalEddy Vluggen12-Sep-19 23:21 
GeneralRe: WPF or Winforms Pin
Gerry Schmitz13-Sep-19 11:15
mveGerry Schmitz13-Sep-19 11:15 
GeneralRe: WPF or Winforms Pin
Eddy Vluggen13-Sep-19 12:19
professionalEddy Vluggen13-Sep-19 12: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.