winform 打印 页边距设置
需要打印预览右边文字的边距和左边一样

我的代码是这样写的,没有效果
应该怎么修改,麻烦帮我看看,谢谢!

我的代码是这样写的,没有效果
private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
//打印方向(纵/横)
this.printDocument1.DefaultPageSettings.Landscape = false;
//设置纸张类型
PaperSize ps = new PaperSize("A4", (int)(5 * 100), (int)(10 * 100));
printDocument1.DefaultPageSettings.PaperSize = ps;
//边距,上下左右
int leftMargin = e.MarginBounds.Left;
int topMargin = e.MarginBounds.Top;
int rightMargin = e.MarginBounds.Right;
int bottomMargin = e.MarginBounds.Bottom;
int nWidth = e.MarginBounds.Width - rightMargin - leftMargin;
int nHeight = e.MarginBounds.Height - topMargin - bottomMargin;
printDocument1.DefaultPageSettings.Margins = new Margins(leftMargin, rightMargin, topMargin, bottomMargin);
float linesPerPage = 0; //记录每页最大行数
float yPos = 0;//记录将要打印的一行数据在垂直方向的位置
int count = 0; //记录每页已打印行数
string line = null;//从RichTextBox中读取一段字符将存到line中
//每页最大行数=一页纸打印区域的高度/一行字符的高度
linesPerPage = e.MarginBounds.Height / printFont.GetHeight(e.Graphics); //如果当前页已打印行数小于每页最大行数而且读出数据不为null,继续打印
while (count < linesPerPage && ((line = streamToPrint.ReadLine()) != null))
{
yPos = topMargin + (count * printFont.GetHeight(e.Graphics)); //yPos为要打印的当前行在垂直方向上的位置
e.Graphics.DrawString(line, printFont, Brushes.Black, leftMargin, yPos, new StringFormat()); //打印,参见第五章
count++;//已打印行数加1
}
if (line != null)//是否需要打印下一页
e.HasMorePages = true;//需要打印下一页
else
e.HasMorePages = false;//不需要打印下一页
}
应该怎么修改,麻烦帮我看看,谢谢!
...全文



