我有一個表單,我有一些文本框。我希望將這些文本框中的文本打印在表單上的位置。它正在使用下面的代碼打印。但是,文本在不同的打印機上打印的方式不同(在某些打印機上打印正確,某些打印機太高等)。它被印在預先印有文字空格的表格上,因此它需要相當準確。我錯過了什麼讓它在每臺打印機上打印相同?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