sajjadrad
سه شنبه 16 شهریور 1389, 14:56 عصر
// print variables
private string strFileName;
private StreamReader objStreamToPrint;
private Font objPrintFont;
private Brush Font_color;
private Color Force_color;
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
private void printToolStripMenuItem_Click(object sender, EventArgs e)
{
PrintDocument Print_Document = new PrintDocument();
Print_Document.DocumentName = "print";
printDialog1.Document = Print_Document;
Force_color = richTextBox1.ForeColor;
if (printDialog1.ShowDialog() == DialogResult.OK)
{
objStreamToPrint = new StreamReader(strFileName);
objPrintFont = richTextBox1.Font;
Print_Document.PrinterSettings = printDialog1.PrinterSettings;
Print_Document.PrintPage +=new PrintPageEventHandler(prtPage);
Print_Document.Print();
objStreamToPrint.Close();
objStreamToPrint = null;
}
}
private void prtPage(object sender, PrintPageEventArgs e)
{
float sngLinesPerpage = 0;
float sngVerticalPosition = 0;
int intLineCount = 0;
float sngLeftMargin = e.MarginBounds.Left;
float sngTopMargin = e.MarginBounds.Top;
string strLine;
sngLinesPerpage = e.MarginBounds.Height / objPrintFont.GetHeight(e.Graphics);
strLine = objStreamToPrint.ReadLine();
while ((intLineCount < sngLinesPerpage) && (strLine != null))
{
sngVerticalPosition = sngTopMargin + (intLineCount * objPrintFont.GetHeight(e.Graphics));
e.Graphics.DrawString(strLine, objPrintFont, Brushes.Black, sngLeftMargin, sngVerticalPosition, new StringFormat());
intLineCount = intLineCount + 1;
if (intLineCount < sngLinesPerpage)
{
strLine = objStreamToPrint.ReadLine();
}
}
if (strLine != null)
{
e.HasMorePages = true;
}
else
{
e.HasMorePages = false;
}
}
سلام خسته نباشید.تو کد بالا برای اینکه بتونم رنگ رشته رو برای چاپ به عنوان پارامتر (Brushes.Black) بفرستم باید Force_color رو که از نوع Color هستش به نوع Brush تبدیل کنم.
لطفا کسی کمک کنه:خجالت:
private string strFileName;
private StreamReader objStreamToPrint;
private Font objPrintFont;
private Brush Font_color;
private Color Force_color;
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
private void printToolStripMenuItem_Click(object sender, EventArgs e)
{
PrintDocument Print_Document = new PrintDocument();
Print_Document.DocumentName = "print";
printDialog1.Document = Print_Document;
Force_color = richTextBox1.ForeColor;
if (printDialog1.ShowDialog() == DialogResult.OK)
{
objStreamToPrint = new StreamReader(strFileName);
objPrintFont = richTextBox1.Font;
Print_Document.PrinterSettings = printDialog1.PrinterSettings;
Print_Document.PrintPage +=new PrintPageEventHandler(prtPage);
Print_Document.Print();
objStreamToPrint.Close();
objStreamToPrint = null;
}
}
private void prtPage(object sender, PrintPageEventArgs e)
{
float sngLinesPerpage = 0;
float sngVerticalPosition = 0;
int intLineCount = 0;
float sngLeftMargin = e.MarginBounds.Left;
float sngTopMargin = e.MarginBounds.Top;
string strLine;
sngLinesPerpage = e.MarginBounds.Height / objPrintFont.GetHeight(e.Graphics);
strLine = objStreamToPrint.ReadLine();
while ((intLineCount < sngLinesPerpage) && (strLine != null))
{
sngVerticalPosition = sngTopMargin + (intLineCount * objPrintFont.GetHeight(e.Graphics));
e.Graphics.DrawString(strLine, objPrintFont, Brushes.Black, sngLeftMargin, sngVerticalPosition, new StringFormat());
intLineCount = intLineCount + 1;
if (intLineCount < sngLinesPerpage)
{
strLine = objStreamToPrint.ReadLine();
}
}
if (strLine != null)
{
e.HasMorePages = true;
}
else
{
e.HasMorePages = false;
}
}
سلام خسته نباشید.تو کد بالا برای اینکه بتونم رنگ رشته رو برای چاپ به عنوان پارامتر (Brushes.Black) بفرستم باید Force_color رو که از نوع Color هستش به نوع Brush تبدیل کنم.
لطفا کسی کمک کنه:خجالت: