我正在尝试测量某些文本的高度以用于表格打印目的。
这是代码。就我而言,它在预览和实际页面上打印不同的数字。我现在无法尝试使用 Microsoft Office Document Image Writer 以外的任何打印机,但我很确定这不是打印机问题。
也许有人找到了解决这个问题的方法?
private void button1_Click(object sender, EventArgs e)
{
Print();
}
public void Print()
{
PrintDocument my_doc = new PrintDocument();
my_doc.PrintPage += new PrintPageEventHandler(this.PrintPage);
PrintPreviewDialog my_preview = new PrintPreviewDialog();
my_preview.Document = my_doc;
my_preview.ShowDialog();
my_doc.Dispose();
my_preview.Dispose();
}
private void PrintPage(object sender,
System.Drawing.Printing.PrintPageEventArgs e)
{
e.Graphics.PageUnit = GraphicsUnit.Pixel;
string s = "String height is ";
SizeF h = e.Graphics.MeasureString(s, new Font("Arial", 24));
e.Graphics.DrawString(s + Convert.ToString(h.Height),
new Font("Arial", 24), new SolidBrush(Color.Black), 1, 1);
}