【TeeChart .NET教程】(十四)打印图表

上一篇:【TeeChart .NET教程】(十三)图表面板上的自定义绘图

【下载TeeChart.Net最新版本】

(一)标准打印

TeeChart Pro提供标准打印方法,可将“Onscreen Chart屏幕图表”按原样打印到打印机。

1.1 简单打印命令

要打印图表,请使用Print方法。这将打印出屏幕上显示的图表:

[C#.Net]

tChart1.Printer.Print();

[VB.Net]

TChart1.Printer.Print()

1.2 打印方向

Print方法允许您使用布尔横向参数打印横向和纵向方向,即使它们未定义为默认方向。打印完成后,默认方向将再次生效。可以使用Landscape属性更改默认方向(对于Landscape,设置为true,对于Portrait,设置为false):

[C#.Net]

tChart1.Printer.Landscape = true; 
tChart1.Printer.Print();

[VB.Net]

扫描二维码关注公众号,回复: 2745022 查看本文章
TChart1.Printer.Landscape = True
TChart1.Printer.Print() 

1.3 打印预览

PrintPreview窗口将显示打印时图表的显示方式,在“Print Preview window打印预览”窗口中修改打印参数,要调用PrintPreview运行:

[C#.Net]

tChart1.Printer.Preview();

[VB.Net]

TChart1.Printer.Preview()

1.4 灰度打印

当打印到Greyscale打印机时,图表的颜色在转换为灰色阴影时很容易区分,为了提供帮助,可以在图表系列中添加画笔样式,以便在打印时更轻松地区分系列,还可以使用灰度属性将彩色图表打印到彩色打印机:

[C#.Net]

tChart1.Printer.Grayscale = true; 
tChart1.Printer.Print(true);

[VB.Net]

TChart1.Printer.Grayscale = True 
TChart1.Printer.Print(True)

(二)扩展打印方法

2.1 打印多个图表

使用BeginPrint()和EndPrint()将图表发送到打印机而不弹出页面; BeginPrint()和EndPrint()开始和结束打印机作业。可以将多个图表发送到同一页面/打印机作业,也可以包含用户自定义输入,例:

[C#.Net]

private void button1_Click(object sender, System.EventArgs e) { 
        tChart1.Printer.BeginPrint(); 
        tChart1.Printer.Print(tChart2.Chart,new Rectangle(100,10,300,200)); 
        tChart1.Printer.Print(new Rectangle(100,300,300,200)); 
        tChart1.Printer.EndPrint(); 
}

[VB.Net]

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click 
        TChart1.Printer.BeginPrint() 
        TChart1.Printer.Print(TChart2.Chart, New Rectangle(100, 10, 300, 200)) 
        TChart1.Printer.Print(New Rectangle(100, 300, 300, 200)) 
        TChart1.Printer.EndPrint() 
End Sub

2.2 在一个页面上打印预览多个图表

打印预览器现在可以接受多个图表,控制图表位置设置Print方法的Rectangle,例:

[C#.Net]

private void button1_Click(object sender, System.EventArgs e) { 
        tChart1.Printer.BeginPrint(); 
        tChart1.Printer.Print(tChart2.Chart,new Rectangle(100,10,300,200)); 
        tChart1.Printer.Print(new Rectangle(100,300,300,200)); 
        tChart1.Printer.Preview(); 
}

[VB.Net]

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click 
        TChart1.Printer.BeginPrint() 
        TChart1.Printer.Print(TChart2.Chart, New Rectangle(100, 10, 300, 200)) 
        TChart1.Printer.Print(New Rectangle(100, 300, 300, 200)) 
        TChart1.Printer.Preview() 
End Sub

2.3 将打印的图表输出与其他打印输出混合

使用ChartPrint()事件将TeeChart打印输出与非Chart打印机输出混合,以下示例从TeeChart标题中获取文本,并在具有两个TeeChart对象的页面上打印它们:

[C#.Net]

private void button1_Click(object sender, System.EventArgs e) { 
        tChart1.Printer.BeginPrint(); 
        tChart1.Printer.Print(tChart2.Chart,new Rectangle(100,10,300,200)); 
        tChart1.Printer.Print(new Rectangle(100,300,300,200)); 
        tChart1.Printer.EndPrint(); 
} 
 
private void tChart1_ChartPrint(object sender, System.Drawing.Printing.PrintPageEventArgs e) { 
        e.Graphics.DrawString("Chart: "+((Steema.TeeChart.ChartPrintJob)sender).Chart.Header.Text, 
            this.Font,new SolidBrush(Color.Black),100,((Steema.TeeChart.ChartPrintJob)sender).ChartRect.Bottom+10); 
}

[VB.Net]

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click 
        TChart1.Printer.BeginPrint() 
        TChart1.Printer.Print(TChart2.Chart, New Rectangle(100, 10, 300, 200)) 
        TChart1.Printer.Print(New Rectangle(100, 300, 300, 200)) 
        TChart1.Printer.EndPrint() 
End Sub 
 
Private Sub TChart1_ChartPrint(ByVal sender As Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles TChart1.ChartPrint 
        e.Graphics.DrawString("Chart: " & (CType(sender, Steema.TeeChart.ChartPrintJob)).Chart.Header.Text, _ 
        Me.Font, New SolidBrush(Color.Black), 100, (CType(sender, Steema.TeeChart.ChartPrintJob)).ChartRect.Bottom + 10) 
End Sub

猜你喜欢

转载自blog.csdn.net/xiaochuachua/article/details/81631734