private void Form1_Load(object sender, EventArgs e)
{
if (count == 2)
{
MessageBox.Show("Congrats You Score is : " + Marks, "Result", MessageBoxButtons.OK);
SendKeys.Send("%{F4}");//tried Application.Exit() this.Close();
}
string choice = src.ReadLine();
string ques = srq.ReadLine();
opt = choice.Split('\t');
label1.Font = new Font("Times New Roman", 15);
label1.Text = ques;
ch1.Font = new Font("Times New Roman", 15);
ch1.Text = opt[0];
ch2.Font = new Font("Times New Roman", 15);
ch2.Text = opt[1];
ch3.Font = new Font("Times New Roman", 15);
ch3.Text = opt[2];
ch4.Font = new Font("Times New Roman", 15);
ch4.Text = opt[3];
}
I am trying to Make a Simple Quiz in GUI this is Not Homework BTW I have Made a Console Quiz Program and Now wish to do it in GUI. I am a beginner and am just searching the net a lot and trying to create this Windows Form:
private void button1_Click(object sender, EventArgs e)
{
if (ch1.Checked == false && ch2.Checked==false && ch3.Checked==false && ch4.Checked==false)
{
MessageBox.Show("Please Choose An Answer", "Error", MessageBoxButtons.OK,MessageBoxIcon.Error);
}
else if (ch1.Checked){
check(ch1);
// MessageBox.Show("Marks : "+Marks);
++count;
Form1_Load(new Object(), new EventArgs());
ch1.Checked = false;
}
else if(ch2.Checked){
check(ch2);
++count;
Form1_Load(new Object(), new EventArgs());
ch2.Checked = false;
}
else if(ch3.Checked){
check(ch3);
++count;
Form1_Load(new Object(), new EventArgs());
ch3.Checked = false;
}
else if (ch4.Checked){
check(ch4);
++count;
Form1_Load(new Object(), new EventArgs());
ch4.Checked = false;
}
}
The Above Method Keeps Loading a new Question and its options and After the Next button is pressed.
Now I want the Quiz to quit itself after count reaches 2 or may be more. I have tried this.Close()
, SendKey,Environment.Exit(0, inputsimulator
(Yes I did Download the .dll
File and add its Reference,using namespace) as well does not work.
Also inputsimulator has the disadvantage that it works only when the App is selected...
sendkeys
works whether the app is selected or not so is it not better......
I understand that an event like mouse click or something is required for this.close()
to work but I want the Quiz to Display the Score and shut it self after all Questions are Answered...
Currently the Quiz does not close and an exception is thrown as the File from which questions and options are read does not have anything left......