为什么矩形没有绘制?我的代码有什么错误吗?我尝试通过 SQLDataReader while 子句创建一个矩形..
private void PrintsDoc (object sender, PrintPageEventArgs e)
{
Graphics g = e.Graphics;
StringFormat sf = new StringFormat ();
sf.Alignment = StringAlignment.Center;
sf.LineAlignment = StringAlignment.Near;
Font fontStyle = new Font ("Times New Roman", 30);
Font fontStyle2 = new Font ("Times New Roman", 10);
g.DrawString ("Trade Confirmation", fontStyle, Brushes.Black, e.MarginBounds, sf);
g.DrawString ("\n\n\nTrade Date: " + dt + "\nPrint Date: " + DateTime.Now.ToString (), fontStyle2, Brushes.Black, e.MarginBounds, sf);
SqlConnection conn = new SqlConnection("Server=WORKERCOMP\\SQLEXPRESS;" + "Database=database;" + "User ID=uid;" + "Password=pwd;" + "Trusted_Connection=yes;");
conn.Open ();
int i = 0, j = 0;
SqlCommand cmd = new SqlCommand("SELECT COLUMN_NAME, DATA_TYPE FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'dbo.TRADE'", conn);
SqlDataReader rdr = cmd.ExecuteReader ();
while (rdr.Read ()) {
Rectangle rec = new Rectangle (new Point (40 + i, 250), new Size (200, 25));
g.DrawRectangle (Pens.Black, rec);
g.DrawString (rdr.GetString(0 + j), fontStyle2, Brushes.Black, rec, sf);
i = i + 215;
j = j + 1;
}
e.HasMorePages = false;
conn.Close ();
}