0
Reply

Customizing Printing tray using C#

srivalli.chavali

srivalli.chavali

Dec 3 2004 4:54 PM
2.2k
Hi, I have a C# form that containsa button, which when clicked, prints a particular document on my machine. I have to customize the printing options. I was successful in customizing font, margins etc. But I'm having issues with customizing the input tray. I want to print that document always from the Tray1 of my printer. But if you access the "Kind" property of each element of the collection, "printDoc.PrinterSettings.PaperSources", it returns only "FormSource" and "Custom" as the values. Now, How can I set it to print to "Tray1" here? Following is my code.. ---------------------------------- private void Button1_Click(object sender, System.EventArgs e) { sr = new StreamReader ("a.txt"); f= new Font("Courier New", 14); PrintDocument printDoc = new PrintDocument(); PaperSource pkSource=null; for (int i = 0; i < printDoc.PrinterSettings.PaperSources.Count; i++) { PaperSource item; item= printDoc.PrinterSettings.PaperSources[i]; pkSource=item; printDoc.DefaultPageSettings.PaperSource =pkSource; printDoc.PrintPage += new PrintPageEventHandler(pqr); printDoc.Print(); } } void pqr(object o, PrintPageEventArgs e) { float lpp = e.MarginBounds.Height / f.GetHeight(e.Graphics) ; int c = 0 ; String s=null; while (c < lpp && ((s=sr.ReadLine()) != null)) { float y = e.MarginBounds.Top + (c * f.GetHeight(e.Graphics)); e.Graphics.DrawString (s, f, Brushes.Black, e.MarginBounds.Left, y); c++; } if (s != null) e.HasMorePages = true ; else e.HasMorePages = false ; } --------------------------------------------- Any help is greatly appreciated. Thanks, Srivalli.