private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
try
{
//r is Reader object
System.Drawing.Font printFont = new Font("Arial", 9, FontStyle.Italic);
System.Drawing.Font HeadFont = new Font("Arial", 12, FontStyle.Bold);
com.Connection = con;
com.CommandText = "Select * from DataTab";
r = com.ExecuteReader();
int y = 40;
//////////////Draw Heading///////////////
e.Graphics.DrawString("Name", HeadFont, Brushes.Black, 10, 10);
e.Graphics.DrawString("Marks", HeadFont, Brushes.Black, 80, 10);
//////////////Drawing Line//////////////////
Pen p=new Pen(Color.Black,2);
e.Graphics.DrawLine(p, 10, 30, 130, 30);
while (r.Read())
{
e.Graphics.DrawString(r.GetValue(0).ToString(), printFont, Brushes.Black, 10, y);
e.Graphics.DrawString(r.GetValue(1).ToString(), printFont, Brushes.Black, 90, y);
y += 20;
}
e.Graphics.DrawLine(p, 75, 10, 75, y);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
finally
{
r.Close();
}
}
No comments:
Post a Comment