C# Tutorial – Create a simple multiple choice quiz game in Visual Studio
- Subject: C# Tutorials
- Learning Time: 1 hour
In this tutorial we will go through how to make a simple multiple choice quiz game inside of Visual Studio using C# programming language and Windows Form .Net Framework. Create a quiz is always fun and its important to understand how to make such a app inside of Windows Form. This tutorial will walk you through how to make the quiz game step by step including how to set up the project, adding the components, importing the images and finally setting up the questions and answers inside of the C# Programming.
Full Video Tutorial on How to a Quiz Game in Visual Studio with C# –
Download Multiple Choice Quiz Project on GitHub
Full Source Code –
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 |
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace Quiz_Game_in_Windows_Form_VS { public partial class Form1 : Form { // quiz game variables int correctAnswer; int questionNumber = 1; int score; int percentage; int totalQuestions; public Form1() { InitializeComponent(); askQuestion(questionNumber); totalQuestions = 8; } private void checkAnswerEvent(object sender, EventArgs e) { var senderObject = (Button)sender; int buttonTag = Convert.ToInt32(senderObject.Tag); if(buttonTag == correctAnswer) { score++; } if(questionNumber == totalQuestions) { // work out the percentage percentage = (int)Math.Round((double)(score * 100) / totalQuestions); MessageBox.Show( "Quiz Ended!" + Environment.NewLine + "You have answered " + score + " questions correctly." + Environment.NewLine + "Your total percentage is " + percentage + "%" + Environment.NewLine + "Click OK to play again" ); score = 0; questionNumber = 0; askQuestion(questionNumber); } questionNumber++; askQuestion(questionNumber); } private void askQuestion(int qnum) { switch(qnum) { case 1: pictureBox1.Image = Properties.Resources.questions; lblQuestion.Text = "What is the colour of the sky?"; button1.Text = "Blue"; button2.Text = "Yellow"; button3.Text = "Orange"; button4.Text = "Red"; correctAnswer = 1; break; case 2: pictureBox1.Image = Properties.Resources.questions; lblQuestion.Text = "What is the name of the main character from Iron Man?"; button1.Text = "Tony Stank"; button2.Text = "Tony Stark"; button3.Text = "Rody"; button4.Text = "Peter Quill"; correctAnswer = 2; break; case 3: pictureBox1.Image = Properties.Resources.csgo; lblQuestion.Text = "What is the name of this game?"; button1.Text = "Call of Duty"; button2.Text = "Battlefield"; button3.Text = "Fortnite"; button4.Text = "CS - GO"; correctAnswer = 4; break; case 4: pictureBox1.Image = Properties.Resources.fortnite; lblQuestion.Text = "Which Publisher made this game?"; button1.Text = "EA"; button2.Text = "Activision"; button3.Text = "Epic Games"; button4.Text = "Equare Enix"; correctAnswer = 3; break; case 5: pictureBox1.Image = Properties.Resources.gears_of_war; lblQuestion.Text = "Whats the name of this game?"; button1.Text = "Gears of War"; button2.Text = "Assassins Creed"; button3.Text = "Uncharted"; button4.Text = "Call of Duty"; correctAnswer = 1; break; case 6: pictureBox1.Image = Properties.Resources.halo; lblQuestion.Text = "What is the main characters name in the game above?"; button1.Text = "Drake"; button2.Text = "Lara Croft"; button3.Text = "Master Cheif"; button4.Text = "Markus"; correctAnswer = 3; break; case 7: pictureBox1.Image = Properties.Resources.witcher3; lblQuestion.Text = "Who was Geralt looking for in Witcher 3?"; button1.Text = "Victoria"; button2.Text = "Mr Donut"; button3.Text = "Ciri"; button4.Text = "Yennifer"; correctAnswer = 3; break; case 8: pictureBox1.Image = Properties.Resources.questions; lblQuestion.Text = "Which city is the captial city of England?"; button1.Text = "Birmingham"; button2.Text = "Brighton"; button3.Text = "Liverpool"; button4.Text = "London"; correctAnswer = 4; break; } } } } |
The volume was low and hard to hear the instructor but it was a good lesson overall.
Agree with the volume issue but solid lesson, thank you for making it!
Nice tutorial! Do you know maybe how can i randomize the order of the questions (cases) without repeat?
Great tutorial