【发布时间】:2009-12-01 01:07:29
【问题描述】:
我有一个表单,上面有许多文本框。我希望在表单上的位置打印这些文本框中的文本。目前正在使用下面的代码打印。但是,文本在不同打印机上的打印方式不同(在某些打印机上打印得恰到好处,在某些打印机上打印得太高,等等)。它被打印在带有文本空格的预打印表格上,因此它需要相当准确。为了让它在每台打印机上打印相同,我缺少什么?
public void printDocument_PrintPage(object sender, PrintPageEventArgs e)
{
Panel curPanel = this.FormPanel;
Graphics g = (Graphics)e.Graphics;
Pen aPen = new Pen(Brushes.Black, 1);
// Cycle through each control. Determine if it's a checkbox or a textbox and draw the information inside
// in the correct position on the form
int xLocation, yLocation;
for (int j = 0; j < curPanel.Controls.Count; j++)
{
// Check if its a TextBox type by comparing to the type of one of the textboxes
if (curPanel.Controls[j] is TextBox)
{
// Unbox the Textbox
TextBox theText = (TextBox)curPanel.Controls[j];
// Draw the textbox string at the position of the textbox on the form, scaled to the print page
xLocation = theText.Bounds.Left;
yLocation = theText.Bounds.Top;
g.DrawString(theText.Text, theText.Font, Brushes.Black, xLocation, yLocation);
}
}
}
【问题讨论】: