I am trying to measure the height of some text for printing purposes. A.
Here is the code. In my case, it prints different numbers in the preview and on the actual page. I cannot try on any printers except Microsoft Office Document Image Writer, but I am sure that this is not a problem with the printer.
Perhaps someone found a workaround for this problem?
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);
}
idn
source
share