I am trying to print a document with .txt extension and for that I am referring to my course book but confused. Here is the source code given in the book :
private void Print_Click(object sender, EventArgs e)
{
printDialog1.Document = printDocument1 // there is no object in my program names ad printDocument1
DialogResult result = printDialog1.ShowDialog();
if (result == DialogResult.OK)
{
printDocument1.Print();
and there is lot more code given
Your example is assuming that a PrintDocument object has been dragged onto the form from the toolbox: you could though just as easily create the object yourself.