| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 850 人关注过本帖
标题:datagrid 打印怎么做
只看楼主 加入收藏
smiles
Rank: 1
等 级:新手上路
帖 子:123
专家分:0
注 册:2005-8-8
收藏
 问题点数:0 回复次数:4 
datagrid 打印怎么做
谢谢
搜索更多相关主题的帖子: datagrid 打印 
2005-08-16 08:54
笨男孩
Rank: 1
等 级:新手上路
帖 子:106
专家分:0
注 册:2005-8-4
收藏
得分:0 
使用水晶报表做吧

2005-08-16 09:27
笨男孩
Rank: 1
等 级:新手上路
帖 子:106
专家分:0
注 册:2005-8-4
收藏
得分:0 

大哥给俺的一个方法(网上的)跟大家分享一下, 我想大哥不会介意的偶

一个DataGrid的打印类- -

namespace AsterDnet { using System; using System.ComponentModel; using System.Windows.Forms; using System.Drawing; using System.Drawing.Printing; using System.IO; using System.Data ; using System.Data.SqlClient ; /// <summary> /// 打印DataGrid中的数据到打印机 /// /// </summary> public class DataGridPrintDocument : PrintDocument { //打印字体 private Font printFont = null; private DataTable dt=null;

//当前页码 private int currentPageNumber=1; //是否打印页码 private bool isPrintPageNumber=false; public bool IsPrintPageNumber { get { return this.isPrintPageNumber ; } set { this.isPrintPageNumber =value; } } //表格文字对齐方式:0:居左;1:居中;2:居右 private int ColStyle=0; public int TableColStyle { get { return this.ColStyle; } set { this.ColStyle=value; } } //是否需要竖线 private bool isNeedVertLine=false; public bool IsNeedVertLine { get { return this.isNeedVertLine; } set { this.isNeedVertLine=value; } } //是否需要横线 private bool isNeedHorLine=false; public bool IsNeedHorLine { get { return this.isNeedHorLine; } set { this.isNeedHorLine=value; } } //表体中文字和表格线的间隔比例 private float LineEmpty=1.3F; public float LineEmptyCharacter { get { return this.LineEmpty; } set { this.LineEmpty=value; } } //指定每页打印表格行数,如果超过纸张的高度就取默认值 private int LinePerPage=0; public int LinePerNumberPage { get { return this.LinePerPage ; } set { this.LinePerPage=value; } } //当前行号 private int currentLineNumber=0; //表格列标题 private string[] colname=null; //标题一 private string headtitle1=null; public string HeadTitle1 { get { return this.headtitle1; } set { this.headtitle1=value; } } //标题二 private string headtitle2=null; public string HeadTitle2 { get { return this.headtitle2; } set { this.headtitle2=value; } } //标题三 private string headtitle3=null; public string HeadTitle3 { get { return this.headtitle3; } set { this.headtitle3=value; } } //标题四一 private string headtitle41=null; public string HeadTitle41 { get { return this.headtitle41; } set { this.headtitle41=value; } } //标题四二 private string headtitle42=null; public string HeadTitle42 { get { return this.headtitle42; } set { this.headtitle42=value; } } //标题四三 private string headtitle43=null; public string HeadTitle43 { get { return this.headtitle43; } set { this.headtitle43=value; } } //页尾一一 private string tailtitle11=null; public string TailTitle11 { get { return this.tailtitle11 ; } set { this.tailtitle11 =value; } } //页尾一二 private string tailtitle12=null; public string TailTitle12 { get { return this.tailtitle12; } set { this.tailtitle12 =value; } } //页尾一三 private string tailtitle13=null; public string TailTitle13 { get { return this.tailtitle13 ; } set { this.tailtitle13=value; } } //页尾二 private string tailtitle2=null; public string TailTitle2 { get { return this.tailtitle2; } set { this.tailtitle2 =value; } } //每页打印DataGrid中数据行数 private int numsPerPage; //要打印的DataGrid控件 private DataGrid printDataGrid =null; public DataGrid PrintDataGrid { get { return this.printDataGrid ; } set { this.printDataGrid =value; } } private void LoadTestDB() { } /// <summary> /// 构造器一 /// </summary> public DataGridPrintDocument(DataGrid dataGrid,string[] ColName) { this.printDataGrid = dataGrid ; this.printFont = dataGrid.Font; this.colname =ColName; dt=(DataTable)this.printDataGrid.DataSource; //LoadTestDB(); }

/// <summary> /// 构造器二 /// </summary> /// <param name="dataGrid">要打印的DataGrid控件</param> public DataGridPrintDocument(DataGrid dataGrid) { this.printDataGrid = dataGrid ; this.printFont = dataGrid.Font; }

//Override OnBeginPrint to set up the font we are going to use protected override void OnBeginPrint(PrintEventArgs ev) { base.OnBeginPrint(ev) ;

}


2005-08-16 09:58
smiles
Rank: 1
等 级:新手上路
帖 子:123
专家分:0
注 册:2005-8-8
收藏
得分:0 
谢谢 笨男孩
我研究一下这个程序

2005-08-17 08:57
梦幻情缘
Rank: 6Rank: 6
等 级:贵宾
威 望:29
帖 子:769
专家分:20
注 册:2005-4-4
收藏
得分:0 
你可以到网上找一些用于打印的类库,很方便的,不用写这么多的代码。
2005-08-17 10:58
快速回复:datagrid 打印怎么做
数据加载中...
 
   



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

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