Hello all!! I am trying to create a Windows Form Application that allows a user to answer 10 questions. The program contains a 'next button so that when the user clicks it, the next question appears. My problem is trying to figure out how to code for the next button. There is also a 'previous' button and I am not sure how to code the program so that the user can cycle through the questions. I have a label for the questions to appear in and want the next question to appear in the same label when the next button is clicked. Any ideas? Thanks!!

Are the questions all in an array? If they are, just have a counter that points to the current question. Initialize it to 0 to indicate the first question. When the Next button is pressed, increment the counter, if it exceeds the number of questions then reset it to 0 so that it starts all over again. Same with Presious button but decrement the counter. It's a pretty simple solution to implement.

do you need in c#.net (windows application) or asp.net & c#.net (web application)

you can use a dictionary to make it more adaptive for future changes, meanwhile solve your current problem, the same way Ancient Dragon's approach.

I would go with dictionary to solve this so that the iterate better than array..

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.