Click here to Skip to main content
15,881,803 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
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;
using System.Drawing.Printing;
using System.Drawing.Imaging;

namespace WindowsFormsApplication1
{
public partial class Admission : Form
{
private System.Drawing.Printing.PrintDocument docToPrint;
public Admission()
{
InitializeComponent();
docToPrint = new System.Drawing.Printing.PrintDocument();
docToPrint.PrintPage += document_PrintPage; // ERROR HERE
}

private void exitToolStripMenuItem_Click(object sender, EventArgs e)
{
this.Close();
}


private void printToolStripMenuItem_Click(object sender, EventArgs e)
{
PrintDialog PrintDialog1 = new PrintDialog();
// Allow the user to choose the page range he or she would
// like to print.
PrintDialog1.AllowSomePages = true;

// Show the help button.
PrintDialog1.ShowHelp = true;

// Set the Document property to the PrintDocument for
// which the PrintPage Event has been handled. To display the
// dialog, either this property or the PrinterSettings property
// must be set
PrintDialog1.Document = docToPrint;

DialogResult result = PrintDialog1.ShowDialog();

// If the result is OK then print the document.
if (result == DialogResult.OK)
{
docToPrint.Print();
}
}


}
}
Posted

1 solution

you need to add event handler for print document, for example

C#
private void document_PrintPage(object sender, PrintPageEventArgs ev)
   {
      // printing document code...
   }

check sample code given in PrintDocument.PrintPage Event documentation [^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900