| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 713 人关注过本帖
标题:打印设置!!怎样实现页面分页功能?
只看楼主 加入收藏
lican
Rank: 1
等 级:新手上路
帖 子:22
专家分:0
注 册:2006-12-31
收藏
 问题点数:0 回复次数:3 
打印设置!!怎样实现页面分页功能?

代码如下,怎样来实现一条数据一页,就是一页只有一个姓名跟学号,数据库有多少条语句就有多少页?
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);
}
}

搜索更多相关主题的帖子: 数据库 打印 页面 Pen 
2007-01-03 11:27
YSKING
Rank: 5Rank: 5
来 自:中国绿城
等 级:贵宾
威 望:16
帖 子:1380
专家分:25
注 册:2006-11-11
收藏
得分:0 
用水晶报表不更好

[此贴子已经被作者于2007-1-3 11:58:02编辑过]



仍然自由自我,永远高唱我歌,走遍千里...
2007-01-03 11:57
bygg
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:乖乖的心中
等 级:版主
威 望:241
帖 子:13555
专家分:3076
注 册:2006-10-23
收藏
得分:0 
在你取数据的时候就一条一条地取呀...

飘过~~
2007-01-03 12:45
lican
Rank: 1
等 级:新手上路
帖 子:22
专家分:0
注 册:2006-12-31
收藏
得分:0 

怎样一条一条地取啊?不能一次读取全部吗?


2007-01-03 13:29
快速回复:打印设置!!怎样实现页面分页功能?
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.034399 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved