我有一个表单,我有一些文本框。我希望将这些文本框中的文本打印在表单上的位置。它正在使用下面的代码打印。但是,文本在不同的打印机上打印的方式不同(在某些打印机上打印正确,某些打印机太高等)。它被印在预先印有文字空格的表格上,因此它需要相当准确。我错过了什么让它在每台打印机上打印相同?C#打印不一致
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);
}
}
}
所以我把这个标记为正确的答案,因为这是我实际做的。我不得不为不同的打印机量身定制,因为我似乎无法找到解释差异的属性。如果任何人有另一个建议,最终工作,我会很乐意改变正确的答案。 – KrisTrip 2010-04-22 14:23:18