System.IO.StreamReader fileToPrint; System.Drawing.Font printFont; private void printButton_Click(object sender, EventArgs e) { string printPath = System.Environment.GetFolderPath(Environment.SpecialFolder.Desktop); fileToPrint = new System.IO.StreamReader(printPath + @"\myFile.txt"); printFont = new System.Drawing.Font("Arial", 10); printDocument1.Print(); fileToPrint.Close(); } private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e) { float yPos = 0f; int count = 0; float leftMargin = e.MarginBounds.Left; float topMargin = e.MarginBounds.Top; string line = null; float linesPerPage = e.MarginBounds.Height/printFont.GetHeight(e.Graphics); while (count < linesPerPage) { line = fileToPrint.ReadLine(); if (line == null) { break; } yPos = topMargin + count * printFont.GetHeight(e.Graphics); e.Graphics.DrawString(line, printFont, Brushes.Black, leftMargin, yPos, new StringFormat()); count++; } if (line != null) { e.HasMorePages = true; } }
All the question that scared me now i am trying to scare them .. so that they cant scare others :)
Thursday, October 13, 2011
Printing a Text File (Visual C#)
Subscribe to:
Post Comments (Atom)
Featured Posts
Open Hardware Monitor A Handy Tool for System Monitoring
#Open #Hardware #Monitor: A Handy Tool for #System #Monitoring #OpenHardwareMonitor is a free, #opensource #software designed to monitor t...
-
Configuration config = HBaseConfiguration.create(); Job job = new Job(config,"ExampleReadWrite"); job.setJarByClass(MyReadWriteJo...
-
Print numbers in order : #!/bin/bash for i in $(seq 0 4) do for j in $(seq $i -1 0) do echo -n $j done echo done Will gi...
No comments:
Post a Comment
Thank you for Commenting Will reply soon ......