# [SOLVED] Printing in Visual Studio C# 2008.



## Lewisharvey (Apr 12, 2010)

Hello,

I am currently working on my exam program and I am trying to enable the print button so I can print my test scores but somehow its not working.I have the coding for the print button but don't know how to input it properly so that the print button will work and let me print the scores.

I hope someone can help me with this.

Here is the code I got for my program:

namespace Quiz{

public partial class Form1 : Form
{
int score;
int firstname;

//Number of seconds students have to complete the task.
double tick_count = 1800;
//Redesign Question 10
//Redesign Question 3
//Have more textbox questions
//Timer needs setting up
//Database needs setting up

public Form1()
{

InitializeComponent();

}

private void button1_Click(object sender, EventArgs e)
{
timer.Start();
tabControl1.SelectedTab = tabPage2;
}

private void button2_Click(object sender, EventArgs e)
{
tabControl1.SelectedTab = tabPage3;
}

private void button3_Click(object sender, EventArgs e)
{
tabControl1.SelectedTab = tabPage4;
}

private void pictureBox3_Click(object sender, EventArgs e)
{
//Does not work
}

private void pictureBox4_Click(object sender, EventArgs e)
{
//Does not work
}

private void pictureBox5_Click(object sender, EventArgs e)
{
//Does not work
}

private void pictureBox6_Click(object sender, EventArgs e)
{
//Does not work
}

private void button4_Click(object sender, EventArgs e)
{
tabControl1.SelectedTab = tabPage5;
}

private void Form1_Load(object sender, EventArgs e)
{
//Do Not Need
}

private void button5_Click(object sender, EventArgs e)
{
tabControl1.SelectedTab = tabPage6;
}

private void button6_Click(object sender, EventArgs e)
{
tabControl1.SelectedTab = tabPage7;
}

private void button7_Click(object sender, EventArgs e)
{
 tabControl1.SelectedTab = tabPage8;
}

private void button8_Click(object sender, EventArgs e)
{
tabControl1.SelectedTab = tabPage9;
}

private void button9_Click(object sender, EventArgs e)
{
tabControl1.SelectedTab = tabPage10;
}

private void button10_Click(object sender, EventArgs e)
{
tabControl1.SelectedTab = tabPage11;
}

private void button11_Click(object sender, EventArgs e)
{
tabControl1.SelectedTab = tabPage12;
}

private void button12_Click(object sender, EventArgs e)
{
tabControl1.SelectedTab = tabPage13;
}

private void button13_Click(object sender, EventArgs e)
{
tabControl1.SelectedTab = tabPage14;

}

private void button14_Click(object sender, EventArgs e)
{
tabControl1.SelectedTab = tabPage15;

}

private void button15_Click(object sender, EventArgs e)
{
tabControl1.SelectedTab = tabPage16;

}

private void button16_Click(object sender, EventArgs e)
{
tabControl1.SelectedTab = tabPage17;

}

private void button17_Click(object sender, EventArgs e)
{
tabControl1.SelectedTab = tabPage18;

}

private void button18_Click(object sender, EventArgs e)
{
tabControl1.SelectedTab = tabPage19;

}

private void button19_Click(object sender, EventArgs e)
{
tabControl1.SelectedTab = tabPage20;

}

private void button20_Click(object sender, EventArgs e)
{
tabControl1.SelectedTab = tabPage21;
}

private void Generate_Score()
{
score = 0;
if (radioButton2.Checked) score++;
if (radioButton16.Checked) score++;
if (checkBox54.Checked) score++;
if (checkBox56.Checked) score++;
if (checkBox57.Checked) score++;
if (checkBox1.Checked) score++;
if (checkBox5.Checked) score++;
if (checkBox9.Checked) score++;
if (checkBox11.Checked) score++;
if (checkBox13.Checked) score++;
if (radioButton9.Checked) score++;
if (radioButton7.Checked) score++;
if (radioButton19.Checked) score++;
if (radioButton22.Checked) score++;
if (checkBox46.Checked) score++;
if (checkBox52.Checked) score++;
if (radioButton53.Checked) score++;
if (radioButton27.Checked) score++;
if (radioButton32.Checked) score++;
if (radioButton35.Checked) score++;
if (radioButton37.Checked) score++;
if (radioButton39.Checked) score++;
if (radioButton45.Checked) score++;
if (radioButton48.Checked) score++;
if (radioButton50.Checked) score++;
textBox2.Text = score.ToString();
timer.Stop();
tabControl1.SelectedTab = tabPage22;
}


private void button22_Click(object sender, EventArgs e)
{
tabControl1.SelectedTab = tabPage2;
}

private void button23_Click(object sender, EventArgs e)
{
tabControl1.SelectedTab = tabPage3;
}

private void button24_Click(object sender, EventArgs e)
{
tabControl1.SelectedTab = tabPage4;
}

private void button42_Click(object sender, EventArgs e)
{
tabControl1.SelectedTab = tabPage20;
}

private void button41_Click(object sender, EventArgs e)
{
tabControl1.SelectedTab = tabPage19;
}

private void button40_Click(object sender, EventArgs e)
{
tabControl1.SelectedTab = tabPage18;
}

private void button39_Click(object sender, EventArgs e)
{
tabControl1.SelectedTab = tabPage17;
}

private void button38_Click(object sender, EventArgs e)
{
tabControl1.SelectedTab = tabPage16;
}

private void button37_Click(object sender, EventArgs e)
{
tabControl1.SelectedTab = tabPage15;
}

private void button36_Click(object sender, EventArgs e)
{
tabControl1.SelectedTab = tabPage14;
}

private void button35_Click(object sender, EventArgs e)
{
tabControl1.SelectedTab = tabPage13;
}

private void button34_Click(object sender, EventArgs e)
{
tabControl1.SelectedTab = tabPage12;
}

private void button33_Click(object sender, EventArgs e)
{
tabControl1.SelectedTab = tabPage11;
}

private void button32_Click(object sender, EventArgs e)
{
tabControl1.SelectedTab = tabPage10;
}

private void button31_Click(object sender, EventArgs e)
{
tabControl1.SelectedTab = tabPage9;
}

private void button30_Click(object sender, EventArgs e)
{
tabControl1.SelectedTab = tabPage8;
}

private void button29_Click(object sender, EventArgs e)
{
tabControl1.SelectedTab = tabPage7;
}

private void button28_Click(object sender, EventArgs e)
{
tabControl1.SelectedTab = tabPage6;
}

private void button27_Click(object sender, EventArgs e)
{
tabControl1.SelectedTab = tabPage5;
}

private void timer1_Tick(object sender, EventArgs e)
{
//Do Not Need
}

private void timer1_Tick_1(object sender, EventArgs e)
{
//Do Not Need
}

private void label38_Click(object sender, EventArgs e)
{
//Do Not Need 
}

private void tableLayoutPanel1_Paint(object sender, PaintEventArgs e)
{
//Do Not Need
}

private void label61_Click(object sender, EventArgs e)
{
//Do Not Need

}

private void button43_Click(object sender, EventArgs e)
{
//Do Not Need
}

private void tabPage8_Click(object sender, EventArgs e)
{
//Do Not Need
}

private void textBox17_TextChanged(object sender, EventArgs e)
{
//Do Not Need
}

private void tabPage14_Click(object sender, EventArgs e)
{
//Do Not Need
}

private void tabPage16_Click(object sender, EventArgs e)
{
//Do Not Need
}

private void tabPage18_Click(object sender, EventArgs e)
{
//Do Not Need
}

private void tabControl1_SelectedIndexChanged(object sender, EventArgs e)
{
//Do Not Need
}

private void button43_Click_1(object sender, EventArgs e)
{
Generate_Score();
}

private void textBox9_TextChanged(object sender, EventArgs e)
{

}

private void timer1_Tick_2(object sender, EventArgs e)
{
tick_count--;

if (tick_count == 0)
{
foreach (TabPage page in tabControl1.TabPages)
{
if (page != tabPage1 && page != tabPage22)
{
foreach (Control innerControl in page.Controls)
{
innerControl.Enabled = false;
}
}
}

tabControl1.SelectedIndex = 21;
Generate_Score();
// Time's up! Want help writing this bit? Tell me what you want to happen when the time runs out.
}

TimeSpan t = TimeSpan.FromSeconds(tick_count);
label38.Text = string.Format("Time remaining: {02}h:{12}m:{22}s", t.Hours, t.Minutes, t.Seconds);


}

private void label38_Click_1(object sender, EventArgs e)
{
//Not in use
}

private void tabPage22_Click(object sender, EventArgs e)
{
//Not in use
}

private void label96_Click(object sender, EventArgs e)
{
//Not in use
}

private void label8_Click(object sender, EventArgs e)
{

}

private void button21_Click(object sender, EventArgs e)
{
tabControl1.SelectedTab = tabPage22;
}

private void button22_Click_1(object sender, EventArgs e)
{
Close();
}



}
}

Here is the coding for the print button I got:

{
//Create an instance of our printer class 
PCPrint printer = new PCPrint(); 
//Set the font we want to use 
printer.PrinterFont = new Font("Verdana", 10); 
//Set the TextToPrint property 
printer.TextToPrint = " Hello world \n\n";
//Now loop throught the items in the list and print each
for (int i = 0; i < listBox1.Items.Count; i++)
{
printer.TextToPrint += listBox1.Items_ + "\n";
}
//Issue print command
printer.Print();
}
}
}
Thank you_


----------



## niemiro (Feb 20, 2010)

Duplicate thread. The other thread is here: http://www.techsupportforum.com/forums/f128/printing-using-c-626555.html

Thread closed.


----------

