Hello stackoverflow community, I am developing a simple windows form application that has a listener in a specific directory listening for a txt file, if the listener detects a new file, it will automaticly send the txt file to a local default printer, but it also displays a "Save print output as" dialog and I need the printing proccess to be instant, without having to interact with any dialog.
To do this I am using the current namespace "using System.Drawing.Printing; using System.IO;" and I have seen the definition of the Print() method but seems like the code is protected so I can't have access to remove the "save print output as" dialog. Any ideas?
Here is my code...
The fileWatcher:
private void fileSystemWatcher1_Created(object sender, FileSystemEventArgs e)
{
try
{
MyPrintMethod(e.FullPath);
}
catch (IOException)
{
}
}
My print method:
private void MyPrintMethod(string path)
{
string s = File.ReadAllText(path);
printDocument1.PrintController = new StandardPrintController();
printDocument1.PrintPage += delegate (object sender1, PrintPageEventArgs e1)
{
e1.Graphics.DrawString(s, new Font("Times New Roman", 12), new SolidBrush(Color.Black), new RectangleF(0, 0, printDocument1.DefaultPageSettings.PrintableArea.Width, printDocument1.DefaultPageSettings.PrintableArea.Height));
};
try
{
printDocument1.Print();
}
catch (Exception ex)
{
throw new Exception("Exception Occured While Printing", ex);
}
}