Coding NEXT button

  • Thread starter Thread starter Tammy Nejadian
  • Start date Start date
T

Tammy Nejadian

I am working with Visual C# window and in my application I need to use a
button ( NEXT) . The button should displays one panel with its objects each
time it clicked. I already developed the codes for creating panels and their
objects which will be questions and their answers. When the NEXT button
clicked it suppose to display first panel with one question and its answers
at a time. When the user selects an answer and click on NEXT button then it
should dismiss the first panel and show the next panel which display the
second question. I coded each panel and its question as a method so method
calls when the button clicked. For example showQuestion1() is first method ,
showQuestion2() is second method… I am new to programming and visual C# so
could you please give me the code with an example.
Thanks,
Tammy
 
I am working with Visual C# window and in my application I need to use a
button ( NEXT) . The button should displays one panel with its objects each
time it clicked.  I already developed the codes for creating panels and their
objects which will be questions and their answers. When the NEXT button
clicked it suppose to display first panel with one question and its answers
at a time. When the user selects an answer and click on NEXT button then it
should dismiss the first panel and show the next panel which display the
second question. I coded each panel and its question as a method so method
calls when  the button clicked. For example showQuestion1() is first method ,
showQuestion2() is  second method… I am new to programming and visual C# so
could you please give me the code with an example.
Thanks,
Tammy

Here is a new direction for you. Instead of panels use a Tab Control,
and each "panel" is then a single tabpage. This, I think, will allow
you to view the "panels" (that is, the tabpages) more quickly in the
Design studio.

The Next button will simply Remove the current tabpage, and Add the
next tabpage. The Previous button will similarly allow the user to
navigate backwards. Furthermore, the title of the tabpage can be used
as a title of the group of questions.

Hope that helps,

Dom
 
I hate to ask the following, but I forsee this thread going for a while...

Let's look at the bigger picture. Assuming you get the [Next] button to
work as you require, have you considered how you are handling the answer to
the question as selected by the user on the previous panel? Where are you
storing the user's answer? You need to restore this on going back to the
previous question, right?
 
You are correct! I did not think about handeling the answers. I added Check
boxes and radio buttons and I also displaying the answers so the user can
select one answer however I have no idea how I can collect the answers. Do
you mind to help me with that. Would you please give me the sample example or
some place to search and view more examples?
Thank you very much.
--
Nejadian


Family Tree Mike said:
I hate to ask the following, but I forsee this thread going for a while...

Let's look at the bigger picture. Assuming you get the [Next] button to
work as you require, have you considered how you are handling the answer to
the question as selected by the user on the previous panel? Where are you
storing the user's answer? You need to restore this on going back to the
previous question, right?


Tammy Nejadian said:
I am working with Visual C# window and in my application I need to use a
button ( NEXT) . The button should displays one panel with its objects each
time it clicked. I already developed the codes for creating panels and their
objects which will be questions and their answers. When the NEXT button
clicked it suppose to display first panel with one question and its answers
at a time. When the user selects an answer and click on NEXT button then it
should dismiss the first panel and show the next panel which display the
second question. I coded each panel and its question as a method so method
calls when the button clicked. For example showQuestion1() is first method ,
showQuestion2() is second method… I am new to programming and visual C# so
could you please give me the code with an example.
Thanks,
Tammy
 
You are correct! I did not think about handeling the answers. I added Check
boxes and  radio buttons and I also displaying the answers so the user can
select one answer however I have no idea how I can collect the answers. Do
you mind to help me with that. Would you please give me the sample exampleor
some place to search and view more examples?
Thank you very much.
--
Nejadian



Family Tree Mike said:
I hate to ask the following, but I forsee this thread going for a while....
Let's look at the bigger picture.  Assuming you get the [Next] button to
work as you require, have you considered how you are handling the answerto
the question as selected by the user on the previous panel?  Where areyou
storing the user's answer?  You need to restore this on going back to the
previous question, right?
"Tammy Nejadian" wrote:

- Show quoted text -

If you use the TabControl, you don't need to worry about saving
responses between pages. Just remove one tabpage, and add the
previous tabpage. All the answers are still there. At the end, when
the user hits "Finish", you save all the answers at one time.
 
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)
 
Thanks for the suggestion but I have to use panel.
--
Nejadian


Dom said:
You are correct! I did not think about handeling the answers. I added Check
boxes and radio buttons and I also displaying the answers so the user can
select one answer however I have no idea how I can collect the answers. Do
you mind to help me with that. Would you please give me the sample example or
some place to search and view more examples?
Thank you very much.
--
Nejadian



Family Tree Mike said:
I hate to ask the following, but I forsee this thread going for a while....
Let's look at the bigger picture. Assuming you get the [Next] button to
work as you require, have you considered how you are handling the answer to
the question as selected by the user on the previous panel? Where are you
storing the user's answer? You need to restore this on going back to the
previous question, right?
"Tammy Nejadian" wrote:
I am working with Visual C# window and in my application I need to use a
button ( NEXT) . The button should displays one panel with its objects each
time it clicked. I already developed the codes for creating panels and their
objects which will be questions and their answers. When the NEXT button
clicked it suppose to display first panel with one question and its answers
at a time. When the user selects an answer and click on NEXT button then it
should dismiss the first panel and show the next panel which display the
second question. I coded each panel and its question as a method so method
calls when the button clicked. For example showQuestion1() is first method ,
showQuestion2() is second method… I am new to programming and visual C# so
could you please give me the code with an example.
Thanks,
Tammy

- Show quoted text -

If you use the TabControl, you don't need to worry about saving
responses between pages. Just remove one tabpage, and add the
previous tabpage. All the answers are still there. At the end, when
the user hits "Finish", you save all the answers at one time.
 
Actually because of each question has different number of answers I am
creating the label and radio buttons for questions rather than using them
from toolbar. I also should use one panel and display each question and its
related answers. And next question should display when the NEXT button
clicked in same panel. I was not able to display the created label and radio
buttons in the panel from tool bar so I end up to create the panel, label and
check boxes or radio buttons for each question. I think your explanation is
very helpful and the project you had it seems is very close to what I need to
do. If you don’t mind could you please send a copy of that project for me,
the one you did for window? I greatly appreciated your help. I am new in
Visual C# and programming and usually looking at similar example is helping
me a lot. Thanks again.
Tammy

--
Nejadian


.\\\\axxx said:
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)
 
Actually because of each question has different number of answers I am
creating the label and radio buttons for questions rather than using them
from toolbar. I also should use one panel and display each question and its
related answers. And next question should display when the NEXT button
clicked in same panel. I was not able to display the created label and radio
buttons in the panel from tool bar so I end up to create the panel, label and
check boxes or radio buttons for each question. I think your explanation is
very helpful and the project you had it seems is very close to what I need to
do. If you don?t mind could you please send a copy of that project for me,
the one you did for window? I greatly appreciated your help. I am new in
Visual C# and programming and usually looking at similar example is helping
me a lot. Thanks again.
Tammy

http://www.codeproject.com/KB/dialog/tswizard.aspx

Simple wizard framework - with source, so you can get an idea of one
implementation of what your trying to do.
 
Back
Top