套打是发票类应用的一个很常见的用例,MultiRow能够实现精确的套打功能,下面我们看看它是怎么实现的。
我们以下面的发票为例:
Step:
1. 首先创建一个VS2005/2008/2010的一个WindowsForm的应用程序工程
2. 在工具箱上单击右键,然后点击【选择项】菜单,在弹出的对话框里,找到GcMultiRow,在其前面的CheckBox打勾,然后单击【确定】按钮,这样GcMulitRow就被添加到工具箱上。
3. 把GcMultiRow从工具箱拖拽到Form上,一个SmartTag会自动弹出
4. 在SmartTag里选择【添加新模板】
5. 将会出来一个欢迎界面,点击【下一步】
6. 在这个选择模板类型画面,有3种类型,在这里我们选择空白模板,关于剩下的2种模式,请参考安装包里的帮助文档】
7. 选择【空白模板】后,直接单击【完成】。
8. 会有一个关于模板的Summary的信息,单击完成按钮。
9. 在GcMultiRow上点击右键,选择【编辑模板】菜单
10. 这个时候,模板设计器就会打开,从工具箱里就可以拖拽你所需要的Cell到模板设计器上了,在【属性】窗口,你可以根据你的需求设计Cell的样式
(请参考下面的视频来设计你的模板,视频地址如下:)
http://gcdn.grapecity.com/showtopic-785.html
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; namespace Demo { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { this.gcMultiRow1.AllowUserToAddRows = false; this.gcMultiRow1.RowCount = 5; this.gcMultiRow1.Document = new System.Drawing.Printing.PrintDocument(); //因为模板比较宽,所以设置Landscape为True this.gcMultiRow1.Document.DefaultPageSettings.Landscape = true; //用这个事件来判断在套打的时候,哪些Cell需要打印,哪些Cell不需要打印 this.gcMultiRow1.CellFormatting += new EventHandler<GrapeCity.Win.MultiRow.CellFormattingEventArgs>(gcMultiRow1_CellFormatting); } void gcMultiRow1_CellFormatting(object sender, GrapeCity.Win.MultiRow.CellFormattingEventArgs e) { //检测Row上的Cells if (isPrinting && e.Scope== GrapeCity.Win.MultiRow.CellScope.Row) { object temp = this.gcMultiRow1[e.RowIndex, e.CellName].Style.Tag; //检测预先设置好的Tag标记,如果为NotPrint,把Value改为Null,这样就不打印这个Cell了。 if (temp != null && temp.ToString() == "NotPrint") { e.Value = null; } } //检测ColumnHeader区域的Cells if (isPrinting && e.Scope == GrapeCity.Win.MultiRow.CellScope.ColumnHeader) { object temp= this.gcMultiRow1.ColumnHeaders[e.SectionIndex].Cells[e.CellIndex].Style.Tag; if (temp != null && temp.ToString() == "NotPrint") { e.Value = null; } } } private void button1_Click(object sender, EventArgs e) { //把发票的样子打印出来,这个时候,里面的Cells不需要填值 this.gcMultiRow1.Document.Print(); } bool isPrinting; private void button2_Click(object sender, EventArgs e) { //这个标记告诉Control,现在准备开始打印 isPrinting = true; //设置PrintStyle为Content模式,这样我们就只打印内容,从而实现了套打功能。 this.gcMultiRow1.PrintSettings.PrintStyle= GrapeCity.Win.MultiRow.PrintStyle.Content; this.gcMultiRow1.Document.Print(); isPrinting = false; } } } 复制代码你也可以直接编译附加的工程,点击第一个Button,就可以打印发票的样子,然后输入一些值,就实现了套打功能。
- Demo.zip (23.64 K, 下载次数:112)
zip(2010-10-29 16:34:25 上传)