C# 如何在C语言中打印页面左下角的文本#
下面的代码用于打印订单。 订单可以由第一个DrawString调用写出可变数量的行 正文 必须出现在页面的左下角 下面的代码使用硬编码值C# 如何在C语言中打印页面左下角的文本#,c#,.net,gdi+,gdi,system.drawing,C#,.net,Gdi+,Gdi,System.drawing,下面的代码用于打印订单。 订单可以由第一个DrawString调用写出可变数量的行 正文 必须出现在页面的左下角 下面的代码使用硬编码值e.MarginBounds.Top+460打印此项。 如何删除此硬编码值,以便在页面底部打印文本 var doc = new PrintDocument(); doc.PrinterSettings.PrinterName = "PDFCreator"; doc.PrintPage += new PrintPageEventHandler(P
e.MarginBounds.Top+460
打印此项。
如何删除此硬编码值,以便在页面底部打印文本
var doc = new PrintDocument();
doc.PrinterSettings.PrinterName = "PDFCreator";
doc.PrintPage += new PrintPageEventHandler(ProvideContent);
doc.Print();
void ProvideContent(object sender, PrintPageEventArgs e)
{
e.Graphics.DrawString("string containing variable number of lines", new Font("Arial", 12),
Brushes.Black, e.MarginBounds.Left, e.MarginBounds.Top);
e.Graphics.DrawString("Bottom line1\r\nBottom line2", new Font("Courier", 10), Brushes.Black,
e.MarginBounds.Left, e.MarginBounds.Top + 460);
}
测量你的绳子,然后从底部向上移动这个高度
void ProvideContent(object sender, PrintPageEventArgs e)
{
e.Graphics.DrawString("string containing variable number of lines", new Font("Arial", 12),
Brushes.Black, e.MarginBounds.Left, e.MarginBounds.Top);
string bottom = "Bottom line1\r\nBottom line2";
Font courier = new Font("Courier", 10);
Size sz = TextRenderer.MeasureText(bottom, courier);
e.Graphics.DrawString(bottom, courier, Brushes.Black,
e.MarginBounds.Left, e.MarginBounds.Bottom - sz.Height);
}
void ProvideContent(object sender, PrintPageEventArgs e)
{
e.Graphics.DrawString("string containing variable number of lines", new Font("Arial", 12),
Brushes.Black, e.MarginBounds.Left, e.MarginBounds.Top);
string bottom = "Bottom line1\r\nBottom line2";
Font courier = new Font("Courier", 10);
Size sz = TextRenderer.MeasureText(bottom, courier);
e.Graphics.DrawString(bottom, courier, Brushes.Black,
e.MarginBounds.Left, e.MarginBounds.Bottom - sz.Height);
}