打印多页边距 [英] print multipage margin
本文介绍了打印多页边距的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我的打印文档代码
string strDisplay = 印刷索引;
System.Drawing.Font fntString = new 字体( Times New Roman, 28 ,FontStyle.Bold);
e.Graphics.DrawString(strDisplay,fntString,Brushes.Black, 180 , 100 ) ;
fntString = new System.Drawing.Font( Times New Roman, 12 ,FontStyle.Regular);
e.Graphics.DrawString( DESCRIPTION + \ n + -------------------------- + \ n + textBox1.Text + \ n + -------------------- ------ + \ n + textBox1.Text + \ n + < span class =code-string> --------------------------,fntString,Brushes.Black, 70 , 590 );
float linesPerPage = 0 ;
float yPosition = 590 ;
int count = 0 ;
float leftMargin = 70 ;
float topMargin = 590 ;
string line = null ;
字体printFont = new System.Drawing.Font( Times New Roman, 8 ,FontStyle.Regular);
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();
}
第一页显示的textbox1内容开始上边距590,也在第二页打印也是上边距是590,我希望第一页上边距是590,第二页连续到顶部位置但不是它590
i卡在这里plz help
解决方案
你应该在页面级别上保持一个标志
bool isFirstPagePrinted = false ;
当第一次调用事件时
...
if (!isFirstPagePrinted)
(
yPosition = 590 ;
topMargin = 590 ;
isFirstPagePrinted = true ;
}
else
{
yPosition = 100 ;
topMargin = < span class =code-digit> 10 0 跨度>;
}
希望这个approch会有所帮助
你可以重置
isFirstPagePrinted = false ;
点击打印按钮
快乐的编码! :)
Hi,
this is my print document code
string strDisplay = "Printing Index";
System.Drawing.Font fntString = new Font("Times New Roman", 28, FontStyle.Bold);
e.Graphics.DrawString(strDisplay, fntString, Brushes.Black, 180, 100);
fntString = new System.Drawing.Font("Times New Roman", 12, FontStyle.Regular);
e.Graphics.DrawString("DESCRIPTION" + "\n" + "--------------------------" + "\n" + textBox1.Text + "\n" + "--------------------------" + "\n" + textBox1.Text + "\n" + "--------------------------", fntString, Brushes.Black, 70, 590);
float linesPerPage = 0;
float yPosition = 590;
int count = 0;
float leftMargin = 70;
float topMargin = 590;
string line = null;
Font printFont = new System.Drawing.Font("Times New Roman", 8, FontStyle.Regular);
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();
}
textbox1 content shown in first pages start top margin 590 and also print in second page also top margin is 590,i want first page top margin is 590 and second page contiuned to top position only not it 590
i stuck here plz help
解决方案
you should maintain a flag on page level
bool isFirstPagePrinted = false;
when first time event called...
if(!isFirstPagePrinted) ( yPosition = 590; topMargin = 590; isFirstPagePrinted = true; } else { yPosition = 100; topMargin = 100; }
Hope this approch will be helpful
you can reset
isFirstPagePrinted = false;
on click of your "print" button
Happy coding! :)
这篇关于打印多页边距的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文