I am writing a quiz program in C# in Visual Studio. When I build it it doesn;t return an errors or warnings. However when I debug, it just brings up a blank screen with no text or buttons etc. I have tchecked all the names match those in the forms and tired changing the classes. Can anyone please tell me where I am going wrong? Many thanks.

`Inline Code Example Here`using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;


namespace WindowsFormsApplication1
{
    public partial class Form1: Form

{
    int i = 0;

    // initiate the array of questions
    string[] Question = new string[] { " In which year did England win the worldcup ? ", " What is the world's longest river ?", "What is the frist prime number ?", " Where is the capital of India?" };

    //initiate the array of answers
    string[] option1 = new string[] { "1970", "Nile", "11", "Bombay" };
    string[] option2 = new string[] { "1966", "Volga", "7", "Delhi" };
    string[] option3 = new string[] { "1962", "Amazon", "2", "Bangor" };
    string[] option4 = new string[] { "1974", "Mississippi", "3", "New Delhi" };

    //initiate the array of correct answers

    int[] Correct_Answer = new int[] { 2, 1, 3, 4 };

    //initiate the array of user answers
    int[] User_Answer = new int[4];


    public Form1()
    {
        InitializeComponent();
    }

    private void Form1_Load(object sender, EventArgs e)
    {
        // On the from disable all of the control items except the START button
        btn_Finish.Enabled = false;
        btn_Next.Enabled = false;
        radioButton1.Enabled = false;
        radioButton2.Enabled = false;
        radioButton3.Enabled = false;
        radioButton4.Enabled = false;
    }

    // Capture the user clicking start
    private void btn_Start_Click(object sender, EventArgs e)
    {

        // On user clicking the strat enable all the buttons 
        btn_Next.Enabled = true;

        radioButton1.Enabled = true;
        radioButton2.Enabled = true;
        radioButton3.Enabled = true;
        radioButton4.Enabled = true;

        // Populate the form with the first question
        textBox1.Text = Question[i];
        radioButton1.Text = option1[i];
        radioButton2.Text = option2[i];
        radioButton3.Text = option3[i];
        radioButton4.Text = option4[i];

    }

    private void btn_Next_Click(object sender, EventArgs e)
    {
        // If an answer has been selected ...
        if ((radioButton1.Checked) || (radioButton2.Checked) || (radioButton3.Checked) || (radioButton4.Checked))
        {
            // If we have not finished answering all the questions ...
            if (i < 4)
            {
                if (radioButton1.Checked)
                {
                    User_Answer[i] = 1;
                }
                else if (radioButton2.Checked)
                {
                    User_Answer[i] = 2;
                }
                else if (radioButton3.Checked)
                {
                    User_Answer[i] = 3;
                }
                else if (radioButton4.Checked)
                {
                    User_Answer[i] = 4;
                }
                i++; // move to the next question
            }


            if (i < 4)   // IF there are furthur question ...
            {
                textBox1.Text = Question[i];
                radioButton1.Text = option1[i];
                radioButton2.Text = option2[i];
                radioButton3.Text = option3[i];
                radioButton4.Text = option4[i];
            }
        }
        else
        {
            MessageBox.Show(" You have not answered the current question.\nYou need to provide an answer");

        }


    }


}

}

What is the problem you're facing, does the application not run? or are you just not seeing the correct answers being shown at the end of the test ?

I noticed the arrary below is never used after it is declared, are you supposed to use it to check the user's answers are correct ?

int[] Correct_Answer = new int[] { 2, 1, 3, 4 };

I hope this helps but if it doesn't could you possiby try to explain the problem you're facing a little more please.

Thanks

The screen will be blank until the form is drawn.
Are you setting the breakpoint too early for the form to be shown?
If you keep stepping through or just let it run at full speed (even in debug mode), it shows correctly, right?

This article has been dead for over six months. Start a new discussion instead.