On Apr 23, 1:16 pm, Family Tree Mike
<FamilyTreeM...@discussions.microsoft.comwrote:
I hate to ask the following, but I forsee this thread going for a while...
Well, the OP said he had a panel for each question - so assuming (s)he
isn't destroying the panel as next is pressed, then the selected
answers are still available on the panels.
I dont think methods of ShowQuestion1() ShowQuestion2() is appropriate
- instead have a mehtod ShowQuestion(int QuestionNumber);
Have an array of panels, to which you have added each panel in
sequence.
Have a private field, int currentQuestionNumber; which is initialised
to 1, incremented when the next button is clicked.
then ShowQuestion(currentQuestionNumber) can do something like:
QuestionPanels[currentQuestionNumber].Visible = true;
QuestionPanels[currentQuestionNumber].BringtoFront;
QuestionPanels[currentQuestionNumber].Dock = DockStyles.Fill;
Implementing a Back button does the same as the next button, but
decrements currentQuestionNumber.
Remembering to check for negative, and values greater than the number
of elements in the array of panels.
If, rather than just having panels with questions and answers hard-
coded, you create a user control, containing (say) a label for the
question and 4 checkboxes for the answers, then either create an
instance of this at runtime, and populate the question text and
checkbox text appriopriately, or inherit from this at design time for
each question, then you can also handle this array of usercontrols
(rather than panels) far more easily when getting the answers .
For example, if the user control has a property of int
CorrectAnswerNumber - this can be set to the value (1-4) of the
checkbox which shows teh correct answer.
Depending on if you want to save individual answers, you could have
properties of int SelectedAnswer which returns 1-4 depending on the
answer selected (or zero if nothing selected yet)
Depending on the use, you might want to go more generic - i.e. if
there may be more or less than 4 possible answers.
I did something similar in Uni (although it was far more complex,
reading questions and possible answers from the DB, contaiing
validation rules in the DB, allowing checkboxes, drop down selections
etc. and also allowing picture questions. It was user configurable
(i.e. the administrator could add and remove questions, assign marks
to particular answers etc.) It even had both a web and windows form
front end.
It was in VB .Net
I may still have a copy if you are interested in looking at it - it's
not exactly a best-practices example (it was written by a team of four
2nd year IT students, after all) but it did the job - and we got a 7
(which is maximum marks here in sunny Oz)