private StringReader myReader;
private void printToolStripMenuItem_Click(object sender, EventArgs e)
{
printDialog1.Document = printDocument1;
string strText = this.richTextBox1.Text;
myReader = new StringReader(strText);
if (printDialog1.ShowDialog() == DialogResult.OK)
{
printDocument1.Print();
}
}
private void printPrieviewToolStripMenuItem_Click(object sender, EventArgs e)
{
string strText = this.richTextBox1.Text;//read text for richtextbox
myReader = new StringReader(strText);
printPreviewDialog1.Document = printDocument1;
printPreviewDialog1.ShowDialog();
}
private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
string line = null;
Font printFont = new System.Drawing.Font("Times New Roman", 8, FontStyle.Regular);
SolidBrush myBrush = new SolidBrush(Color.Black);
float linesPerPage = 0;
float topMargin = 590;
float yPosition = 590;
int count = 0;
float leftMargin = 70;
linesPerPage = e.MarginBounds.Height/printFont.GetHeight(e.Graphics);
while (count < linesPerPage && ((line = myReader.ReadLine()) != null))
{
if (count == 0)
{
yPosition = 590;
topMargin = 590;
}
else
{
yPosition = 100;
topMargin = 100;
}
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();
}
}
}
}
请哪里是我犯错误要打印第一页顶部marigin是590,如果多页第二页应打印页顶marigin是100 上面给出的代码打印是好的,但打印marigin不解决 帮助我的核心。打印marigin不是在第二页中设置
有人解决这个。我困在这里[打印多页边距 – Varta 2014-09-29 13:49:29
可能重复的不设置](http://stackoverflow.com/questions/26293174/printing-multiple-pages-margin-not-set) – 2014-10-10 13:33:20
@BerndLinde实际上,严格来说,这个问题是这个问题的重复。 – 2014-10-10 13:59:23