如何使用C Sharp添加打印功能. [英] How to add Print Functionality using C sharp.

查看:106
本文介绍了如何使用C Sharp添加打印功能.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我想使用c清晰代码在功能上添加打印内容,
我的目标是当数据显示在网格视图中时,然后使用按钮单击以打印值.

Hi I want to add print functionally by using c sharp code, Actually
my target is that when data shows in grid view then using button click print the values.

推荐答案

尝试以下操作:

http://amitpatriwala.wordpress.com/2008/07/26 /gridview-data-print-in-aspnet-20/ [ http://aspdotnetcodebook.blogspot.com/2008/02/printing-gridview-from- aspnet.html [ ^ ]

希望对您有所帮助:)
Try these:

http://amitpatriwala.wordpress.com/2008/07/26/gridview-data-print-in-aspnet-20/[^]

http://aspdotnetcodebook.blogspot.com/2008/02/printing-gridview-from-aspnet.html[^]

hope it helps :)


从工具箱添加Printdocument.然后,在Printdocument的PrintPage事件中编写以下代码.
Add a Printdocument from toolbox. Then, write the below code in the PrintPage event of the Printdocument.
private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
Bitmap bm = new Bitmap(this.dataGridView1.Width, this.dataGridView1.Height);
            this.dataGridView1.DrawToBitmap(bm, new Rectangle(0, 0, this.dataGridView1.Width, this.dataGridView1.Height));
            e.Graphics.DrawImage(bm, 0, 0);
}


然后,单击从打印按钮调用打印".


Then, Call the print from print button click.

private void printbutton_Click(object sender, EventArgs e)
{
 printDocument1.Print();
}


将网格添加到div并编写此javascript

Add your grid to a div and write this javascript

<script type="text/javascript">
    function printPartOfPage(elementId) {   
        var printContent = document.getElementById(elementId);//elementId is the name of ur div
        var windowUrl = 'Test';
        var uniqueName = new Date();
        var windowName = 'Print' + uniqueName.getTime();
        var printWindow = window.open(windowUrl, windowName, 'left=50,top=50,width=600,height=400');
        printWindow.document.write(printContent.innerHTML);
        printWindow.document.close();
        printWindow.focus();
        printWindow.print();
        printWindow.close();
    }</script>


这篇关于如何使用C Sharp添加打印功能.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆