public void getPapersize() //Get Default Printer paper size
{
using (System.Drawing.Printing.PrintDocument PD = new System.Drawing.Printing.PrintDocument())
{
foreach (System.Drawing.Printing.PaperSize P in PD.PrinterSettings.PaperSizes)
{
Console.Write(P.PaperName + " ");
double W = P.Width / 100.0;
double H = P.Height / 100.0;
double[] M = { 1, 72, 200 };
for (int I = 0; I <= 2; I++)
{
MessageBox.Show((W * M[I]).ToString() + " " + (H * M[I]).ToString() + " ");
}
}
}
}
------------------------------
public void Print(string s)
{
System.Drawing.Printing.PrintDocument PD = new System.Drawing.Printing.PrintDocument();
PD.PrintController = new System.Drawing.Printing.StandardPrintController();
PD.PrintPage += delegate(object sender1, System.Drawing.Printing.PrintPageEventArgs e1)
{
e1.Graphics.DrawString(s, new Font("Times New Roman", 12), new SolidBrush(Color.Black), new RectangleF(0, 0, PD.DefaultPageSettings.PrintableArea.Width, PD.DefaultPageSettings.PrintableArea.Height));
};
try
{
PD.Print();
}
catch (Exception ex)
{
throw new Exception("Exception Occured While Printing", ex);
}
}
{
using (System.Drawing.Printing.PrintDocument PD = new System.Drawing.Printing.PrintDocument())
{
foreach (System.Drawing.Printing.PaperSize P in PD.PrinterSettings.PaperSizes)
{
Console.Write(P.PaperName + " ");
double W = P.Width / 100.0;
double H = P.Height / 100.0;
double[] M = { 1, 72, 200 };
for (int I = 0; I <= 2; I++)
{
MessageBox.Show((W * M[I]).ToString() + " " + (H * M[I]).ToString() + " ");
}
}
}
}
------------------------------
public void Print(string s)
{
System.Drawing.Printing.PrintDocument PD = new System.Drawing.Printing.PrintDocument();
PD.PrintController = new System.Drawing.Printing.StandardPrintController();
PD.PrintPage += delegate(object sender1, System.Drawing.Printing.PrintPageEventArgs e1)
{
e1.Graphics.DrawString(s, new Font("Times New Roman", 12), new SolidBrush(Color.Black), new RectangleF(0, 0, PD.DefaultPageSettings.PrintableArea.Width, PD.DefaultPageSettings.PrintableArea.Height));
};
try
{
PD.Print();
}
catch (Exception ex)
{
throw new Exception("Exception Occured While Printing", ex);
}
}
Good practice
ReplyDelete