当我点击“打印”时,我已经显示了一个打印窗口,其中的数据来自我的DevExpress.XtraGrid.Views.Grid.GridView gridView;
private void button1_Click(object sender, EventArgs e)
{
gridView.ShowPrintPreview();
}
I want this data to add your text.how it can be implemented?
https://pp.vk.me/c620629/v620629208/926a/GbIsa-3vQKk.jpg
private void button1_Click(object sender, EventArgs e)
{
somemethod();
gridView.ShowPrintPreview();
}
void somemethod()
{
DevExpress.XtraPrinting.PrintableComponentLink pl = new DevExpress.XtraPrinting.PrintableComponentLink();
printingSystem1 = new PrintingSystem();
printingSystem1.Links.Add(pl);
pl.Component = _gridControl;
pl.CreateReportHeaderArea += new CreateAreaEventHandler(pl_CreateReportHeaderArea);
}
void pl_CreateReportHeaderArea(object sender, CreateAreaEventArgs e)
{
TextBrick brick1 = e.Graph.DrawString("Your text goes here", Color.Black,
new RectangleF(0, 0, 620, 20), DevExpress.XtraPrinting.BorderSide.None);
brick1.HorzAlignment = HorzAlignment.Center;
brick1.Font = new Font(FontFamily.GenericSansSerif, 12, FontStyle.Bold);
}
答案 0 :(得分:2)
试试这个
private void button1_Click(object sender, System.EventArgs e)
{
PrintableComponentLink pl = new PrintableComponentLink(new PrintingSystem());
pl.Component = gridControl1;
pl.CreateAreaEventHandler+= new CreateAreaEventHandler(pl_CreateReportHeaderArea);
pl.CreateDocument();
pl.ShowPreview();
}
public void pl_CreateReportHeaderArea(object sender, CreateAreaEventArgs e)
{
TextBrick brick1 = e.Graph.DrawString("Your text goes here", Color.Black,
new RectangleF(0, 0, 620,20), DevExpress.XtraPrinting.BorderSide.None);
brick1.HorzAlignment = HorzAlignment.Center;
brick1.Font = new Font(FontFamily.GenericSansSerif, 12, FontStyle.Bold);
}
答案 1 :(得分:0)
要向xtragrid打印预览添加自定义标头,您需要处理PrintableCompnentLink的CreateAreaEventHandler事件。
PrintingSystem printingSystem1;
void somemethod()
{
DevExpress.XtraPrinting.PrintableComponentLink pl = new DevExpress.XtraPrinting.PrintableComponentLink();
printingSystem1.Links.Add(pl);
pl.Component = _gridControl;
pl.CreateAreaEventHandler+= new CreateAreaEventHandler(pl_CreateReportHeaderArea);
}
void pl_CreateReportHeaderArea(object sender, CreateAreaEventArgs e)
{
TextBrick brick1 = e.Graph.DrawString("Your text goes here", Color.Black,
new RectangleF(0, 0, 620,20), DevExpress.XtraPrinting.BorderSide.None);
brick1.HorzAlignment = HorzAlignment.Center;
brick1.Font = new Font(FontFamily.GenericSansSerif, 12, FontStyle.Bold);
}