I'm trying to print two values through C# PrintDocument option however the texts that I'm trying to print are printed in one messy row. As in, the first text is on top of the second text in the same row. What should I do to avoid this?
try
{
// Assumes the default printer.
PrintDocument pd = new PrintDocument();
pd.DefaultPageSettings.PaperSize = new PaperSize("A4", 827, 1170);
pd.PrintPage += new PrintPageEventHandler(this.pd_PrintPage);
pd.Print();
}
catch (Exception ex)
{
MessageBox.Show("Error", ex.ToString());
}
private void pd_PrintPage(Object sender, PrintPageEventArgs ev)
{
ev.Graphics.DrawString("hello", new Font("Time New Roman", 14, FontStyle.Bold), Brushes.Black, 20, 100);
ev.Graphics.DrawString("Hi!!!!!!", new Font("Time New Roman", 14, FontStyle.Bold), Brushes.Black, 20, 100);
}
You printed both at the exact same coordinates:
20, 100
.Stop doing that if you don't want it. You want the text to appear in different places on your page, so draw it to different places on your page.