У меня есть форма, в которой у меня есть несколько текстовых полей. Я хочу напечатать текст из этих текстовых полей в местах их расположения в форме. Это печать в данный момент с использованием кода ниже. Тем не менее, текст печатается по-разному на разных принтерах (на некоторых он печатается правильно, на некоторых слишком высоко и т. Д.) Он печатается на предварительно напечатанной форме с пробелами для текста, поэтому он должен быть достаточно точным. Чего мне не хватает, чтобы он печатался одинаково на каждом принтере?
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);
}
}
}