代码如下,怎样来实现一条数据一页,就是一页只有一个姓名跟学号,数据库有多少条语句就有多少页?
private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
Font objFont = new Font("Tahoma",11,FontStyle.Regular);
Brush objBrush = Brushes.Black;
Pen objPen=new Pen(objBrush);
objPen.Width=1;
int nLeft=this.pageSetupDialog1.PageSettings.Margins.Left;
int nTop=this.pageSetupDialog1.PageSettings.Margins.Top;
int nWidth=this.pageSetupDialog1.PageSettings.PaperSize.Width-(this.pageSetupDialog1.PageSettings.Margins.Left +this.pageSetupDialog1.PageSettings.Margins.Right );
int nHeight=this.pageSetupDialog1.PageSettings.PaperSize.Height-120-(this.pageSetupDialog1.PageSettings.Margins.Top +this.pageSetupDialog1.PageSettings.Margins.Bottom );
e.Graphics.DrawLine(objPen,nLeft,nTop,nLeft+nWidth,nTop);
e.Graphics.DrawLine(objPen,nLeft,nTop+nHeight,nLeft+nWidth,nTop+nHeight);
e.Graphics.DrawLine(objPen,nLeft,nTop,nLeft,nTop+nHeight);
e.Graphics.DrawLine(objPen,nLeft+nWidth,nTop,nLeft+nWidth,nTop+nHeight);
e.Graphics.DrawString("姓名",objFont,objBrush,nLeft+10,nTop+10);
e.Graphics.DrawString("学号",objFont,objBrush,nLeft+180,nTop+10);
Graphics g=e.Graphics;
Pen myPen = new Pen(Color.Black);
g.DrawLine(myPen,160,100,160,220);//竖线
g.DrawLine(myPen,260,100,260,220);g.DrawLine(myPen,100,140,600,140);//横线
g.DrawLine(myPen,340,100,340,220);g.DrawLine(myPen,100,180,600,180);
g.DrawLine(myPen,500,100,500,220);g.DrawLine(myPen,100,220,600,220);
g.DrawLine(myPen,550,100,550,220);g.DrawLine(myPen,100,260,728,260);
g.DrawLine(myPen,600,100,600,260);g.DrawLine(myPen,100,300,728,300);
g.DrawLine(myPen,180,220,180,950);g.DrawLine(myPen,100,340,728,340);
g.DrawLine(myPen,320,220,320,300);g.DrawLine(myPen,100,380,728,380);
g.DrawLine(myPen,400,220,400,460);g.DrawLine(myPen,100,420,728,420);
g.DrawLine(myPen,480,300,480,460);g.DrawLine(myPen,100,460,728,460);
g.DrawLine(myPen,100,500,728,500);
try
{
string strConnection="Provider=Microsoft.Jet.OLEDB.4.0;";
strConnection+=@"Data Source=Student.mdb";
OleDbConnection objSqlConn=new OleDbConnection(strConnection);
objSqlConn.Open();
OleDbCommand objSqlCommand = new OleDbCommand("Select * from Message",objSqlConn);
OleDbDataReader objOleDbDataReader = objSqlCommand.ExecuteReader();
while(objOleDbDataReader.Read())
{
e.Graphics.DrawString(objOleDbDataReader["姓名"].ToString(),objFont,objBrush,nLeft+70,nTop+10);
e.Graphics.DrawString(objOleDbDataReader["学号"].ToString(),objFont,objBrush,nLeft+250,nTop+10);
}
objSqlConn.Close();
}
catch(OleDbException ex)
{
MessageBox.Show(ex.Message);
}
}
打印设置!!怎样实现页面分页功能?