samedi 15 novembre 2014

How to print from the code in C#


Vote count:

0




I am a beginning code noob and I am making a Wordpad program. I am making this feature in which you click this button, and it prints to your default printer. I have done some research, and I found some functional code that ACCTUALLY prints to my printer:



private void buttonPrint_Click(object sender, EventArgs e)
{
string print = "" + textBody.Text;

PrintDocument p = new PrintDocument();
p.PrintPage += delegate(object sender1, PrintPageEventArgs e1)
{
e1.Graphics.DrawString(print, new Font("Times New Roman", 12), new SolidBrush(Color.Black), new RectangleF(0, 0, p.DefaultPageSettings.PrintableArea.Width, p.DefaultPageSettings.PrintableArea.Height));
};
try
{
p.Print();
}
catch (Exception ex)
{
throw new Exception("Exception Occured While Printing", ex);
}
}


This works currently, but I was wondering if I could make it WITH margins, which it does not have now. All it does is this:


There are no margins on the top, sides (left,right), and bottom. If anyone ha any input or just totally different code, PLEASE LET ME KNOW!



asked 18 secs ago







How to print from the code in C#

Aucun commentaire:

Enregistrer un commentaire