توی این برنامه سه متغیر سراسری تعریف شده به ترتیب برای:
- مشخص کردن نوع و اندازه فونت برای پرینت فایل
- خوندن فایل مورد نظر
- انتخاب فایل مورد نظر
- مسیر و نام فایل مورد نظر
System.IO.StreamReader streamToPrint = null;
System.Windows.Forms.OpenFileDialog op = null;
static string filePath;
private void button1_Click(object sender, EventArgs e)
{
try
{op = new OpenFileDialog();
op.ShowDialog();
//MessageBox.Show(op.FileName);
filePath = op.FileName;
streamToPrint = new System.IO.StreamReader(filePath);
printFont = new System.Drawing.Font("Tahoma", 8);
System.Drawing.Printing.PrintDocument PD = new System.Drawing.Printing.PrintDocument();
PD.PrintPage += new System.Drawing.Printing.PrintPageEventHandler(PD_PrintPage);
PD.Print();
try
{
}
finally
{
streamToPrint.Close();
}}
catch (System.Exception ex)
{
System.Windows.Forms.MessageBox.Show(ex.Message, "Error");
}
}
void PD_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
float linesPerPage = 0;
float yPos = 0;
int count = 0;
float leftMargin = e.MarginBounds.Left;
float topMargin = e.MarginBounds.Top;
String line = null;
// Number Of Lines
linesPerPage = e.MarginBounds.Height;
printFont.GetHeight(e.Graphics);
// Printing Each line
while (count < linesPerPage && ((line = streamToPrint.ReadLine()) != null))
{yPos = topMargin + (count * printFont.GetHeight(e.Graphics));
e.Graphics.DrawString(line, printFont, System.Drawing.Brushes.Black, leftMargin, topMargin, new StringFormat());
count++;}
// If More Line Exist
if (line != null)
{e.HasMorePages = true;
}
else
{e.HasMorePages = false;
}
{
مراحل کار اینطوریه که بعد از انتخاب،فایل توسط یه StreamReader خط به خط خونده می شه و توسط یه Print Document پرینت میشه
اگه تعداد خطوط فایل زیاد باشه توی چند صفحه فایل مورد نظر پرینت میشه.


نرم افزار مدیریت تعمیرگاه(موبایل- رایانه-تلوزیون و ...)
پروژه کامل کتابخانه آنلاین به همراه داکیومنت و مستندات به زبان php