我一直在四处寻找,并且不确定我是否找到了答案。如果这似乎是基本的话,我是新编码所以道歉。 我正在尝试使用Windows窗体中的各种输入生成打印发票。我发现当前代码覆盖了上一行。 我已经包含了打印预览,因为它也显示为覆盖行
private void PrintPreviewControl()
{
Form previewForm = new Form();
PrintPreviewControl previewControl = new PrintPreviewControl();
previewControl.Document = printDocument1;
previewControl.Zoom = 0.5;
previewControl.Dock = DockStyle.Fill;
previewForm.Controls.Add(previewControl);
previewForm.ShowDialog();
previewForm.Dispose();
}
private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
Single vPos = 0; //y-axe
Single hPos = 0; //x-axe
//Font
Font fontMedium = new Font("Arial", 16);
Font fontLargeBold = new Font("Arial", 20, FontStyle.Bold);
//Font myFont = new Font();
//Brush
Brush brushBlue = new SolidBrush(Color.Blue);
Brush brushBlack = Brushes.Black;
Brush myBrush = new SolidBrush(Color.Aqua);
hPos = 100;
vPos = 150;
e.Graphics.DrawString("Name", fontLargeBold, brushBlue, hPos, vPos);
hPos = 300;
vPos = 150;
e.Graphics.DrawString(lbxTitle.Text, fontMedium, brushBlack, hPos, vPos);
e.Graphics.DrawString(txtName.Text, fontMedium, brushBlack, hPos, vPos);
hPos = 300;
vPos = 150;
hPos = 100;
vPos = 200;
e.Graphics.DrawString("Email", fontLargeBold, brushBlue, hPos, vPos);
hPos = 100;
vPos = 200;
e.Graphics.DrawString(txtEmail.Text, fontMedium, brushBlack, hPos, vPos);