套打是发票类应用的一个很常见的用例,MultiRow能够实现精确的套打功能,下面我们看看它是怎么实现的。
我们以下面的发票为例:
设计器就会打开,从工具箱里就可以拖拽你所需要的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,就可以打印发票的样子,然后输入一些值,就实现了套打功能。
-
zip(2010-10-29 16:34:25 上传)