Windows Forms
A set of .NET Framework managed libraries for developing graphical user interfaces.
1,924 questions
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
How do i tell if print was successful.
I am using this code, I works after failed attempt creates error.
string printerinUse = pDialog.PrinterSettings.PrinterName;
var server = new LocalPrintServer();
PrintQueue queue = server.GetPrintQueue(printerinUse);
MessageBox.Show("printer " + printerinUse +" is " + queue.IsOffline.ToString());
//various properties of printQueue
bool isOutOfPaper = queue.IsOutOfPaper;
bool isOffLine = queue.IsOffline;
bool isPaperJam = queue.IsPaperJammed;
bool isNotResponding = queue.IsInError;
MessageBox.Show("printer " + printerinUse + " is " + isNotResponding.ToString());
if (isOffLine)
{
MessageBox.Show("Printer is offline");
return;
}
if (isOutOfPaper)
{
MessageBox.Show("Printer is out of paper");
return;
}
if (isPaperJam)
{
MessageBox.Show("Printer has a paper jam");
return;
}
if (isNotResponding)
{
MessageBox.Show("Printer is in error");
return;
}
Hello @Jordan Halgunseth ,
I checked the documentation and it seems the dialog part can be separated from the actual printing.
Once printing is started and/or ends:
using System.Drawing.Printing;
using System.Windows.Forms;
namespace WinFormsApp1
{
public partial class Form1 : Form
{
PrintDocument docToPrint;
public Form1()
{
InitializeComponent();
docToPrint = new PrintDocument();
docToPrint.BeginPrint += DocToPrint_BeginPrint;
docToPrint.PrintPage += DocToPrint_PrintPage;
docToPrint.EndPrint += DocToPrint_EndPrint;
}
private void DocToPrint_BeginPrint(object sender, PrintEventArgs e)
{
// now you know printing starts
}
private void DocToPrint_PrintPage(object sender, PrintPageEventArgs e)
{
// now you know it's printing
}
private void DocToPrint_EndPrint(object sender, PrintEventArgs e)
{
// now you know printing ends
}
private void button1_Click(object sender, EventArgs e)
{
printDialog1.Document = docToPrint;
DialogResult result = printDialog1.ShowDialog();
// If the result is OK then print the document.
if (result == DialogResult.OK)
{
docToPrint.Print();
}
}
}
}
You need to add your own logic to connect the three kinds of events together and make a decision.
If the response helped, do "Accept Answer". If it doesn't work, please let us know the progress. All community members with similar issues will benefit by doing so. Your contribution is highly appreciated.