这是关于打印的部分代码,问题出在预览时不自动换行,有没有高手帮忙解决以一下啊???先谢了!!!protected void ThePrintDocument_PrintPage ( object sender , PrintPageEventArgs e )
{
float linesPerPage = 0 ;
float yPosition = 0 ;
int count = 0 ;
float leftMargin = e.MarginBounds.Left ;
float topMargin = e.MarginBounds.Top ;
string line = null ;
Font printFont = richTextBox1.Font ;
SolidBrush myBrush = new SolidBrush ( Color.Black ) ;
linesPerPage = e.MarginBounds.Height / printFont.GetHeight ( e.Graphics ) ;
while( count < linesPerPage && ( ( line = myReader.ReadLine ()) != null ))
{
yPosition = topMargin + ( count * printFont.GetHeight ( e.Graphics )) ;
e.Graphics.DrawString ( line , printFont , myBrush , leftMargin , yPosition , new StringFormat () ) ;
count++ ;
} if (line != null)
e.HasMorePages = true;
else
e.HasMorePages = false;
myBrush.Dispose();
}
private void button2_Click(object sender, System.EventArgs e)
{
try
{
string strText = richTextBox1.Text ;
myReader = new StringReader ( strText );
PrintPreviewDialog printPreviewDialog1 = new PrintPreviewDialog ( );
printPreviewDialog1.Document = ThePrintDocument;
printPreviewDialog1.FormBorderStyle = FormBorderStyle.Fixed3D;
printPreviewDialog1.ShowDialog ( );
}
catch ( Exception exp )
{
Console.WriteLine ( exp.Message.ToString ( ) ) ;
}
}
{
float linesPerPage = 0 ;
float yPosition = 0 ;
int count = 0 ;
float leftMargin = e.MarginBounds.Left ;
float topMargin = e.MarginBounds.Top ;
string line = null ;
Font printFont = richTextBox1.Font ;
SolidBrush myBrush = new SolidBrush ( Color.Black ) ;
linesPerPage = e.MarginBounds.Height / printFont.GetHeight ( e.Graphics ) ;
while( count < linesPerPage && ( ( line = myReader.ReadLine ()) != null ))
{
yPosition = topMargin + ( count * printFont.GetHeight ( e.Graphics )) ;
e.Graphics.DrawString ( line , printFont , myBrush , leftMargin , yPosition , new StringFormat () ) ;
count++ ;
} if (line != null)
e.HasMorePages = true;
else
e.HasMorePages = false;
myBrush.Dispose();
}
private void button2_Click(object sender, System.EventArgs e)
{
try
{
string strText = richTextBox1.Text ;
myReader = new StringReader ( strText );
PrintPreviewDialog printPreviewDialog1 = new PrintPreviewDialog ( );
printPreviewDialog1.Document = ThePrintDocument;
printPreviewDialog1.FormBorderStyle = FormBorderStyle.Fixed3D;
printPreviewDialog1.ShowDialog ( );
}
catch ( Exception exp )
{
Console.WriteLine ( exp.Message.ToString ( ) ) ;
}
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货