实现C#打印窗体实例详解
来源:互联网 发布:python 改变图片颜色 编辑:程序博客网 时间:2024/05/01 14:41
如何在 Windows 下实现C#打印窗体作为C#开发过程的一部分,通常会希望C#打印窗体的副本。下面的代码示例演示如何使用 CopyFromScreen 方法来实现C#打印窗体的副本。
- using System;
- using System.Windows.Forms;
- using System.Drawing;
- using System.Drawing.Printing;
- public class Form1 :
- Form
- {//实现C#打印窗体
- private Button printButton = new Button();
- private PrintDocument printDocument1 = new PrintDocument();
- public Form1()
- {
- printButton.Text = "Print Form";
- printButton.Click += new EventHandler(printButton_Click);
- printDocument1.PrintPage +=
- new PrintPageEventHandler(printDocument1_PrintPage);
- this.Controls.Add(printButton);
- }
- void printButton_Click(object sender, EventArgs e)
- {
- CaptureScreen();
- printDocument1.Print();
- }
- //实现C#打印窗体
- Bitmap memoryImage;
- private void CaptureScreen()
- {
- Graphics myGraphics = this.CreateGraphics();
- Size s = this.Size;
- memoryImage = new Bitmap(s.Width, s.Height, myGraphics);
- Graphics memoryGraphics = Graphics.FromImage(memoryImage);
- memoryGraphics.CopyFromScreen(
- this.Location.X, this.Location.Y, 0, 0, s);
- }
- private void printDocument1_PrintPage(System.Object sender,
- System.Drawing.Printing.PrintPageEventArgs e)
- {
- e.Graphics.DrawImage(memoryImage, 0, 0);
- }
- //实现C#打印窗体
- public static void Main()
- {
- Application.Run(new Form1());
- }
- }
◆C#打印窗体之编译代码
这是一个完整的代码示例,其中包含 Main 方法。
◆C#打印窗体之可靠编程
1、以下情况可能会导致异常:
2、您没有访问该打印机的权限。
3、没有安装打印机。
◆C#打印窗体之安全
为了运行此代码示例,您必须能够访问与计算机一起使用的打印机。
C#打印窗体的具体内容就向你介绍到这里,希望对你了解和学习C#打印窗体有所帮助。
转自:http://developer.51cto.com/art/200908/146909.htm
- 实现C#打印窗体实例详解
- 实现C#打印窗体实例详解
- C#实现打印功能实例详解
- C#实现打印功能实例详解
- 实现C#打印文档实例详解
- 实现C#打印文档实例详解
- C#打印文本文件实例详解
- C# winform窗体实现简单打印
- C#打印窗体
- C#中打印窗体
- C# winform 窗体打印
- C#窗体实例:记事本
- C# 单例模式实现实例产生一个窗体对象
- 关于C#的windons窗体的打印功能知识点解析和功能实例
- 实现打印窗体内容效果
- C#实现窗体移动
- c# 窗体多线程实现
- c#实现窗体抖动
- Android环境搭建以及第一个实例
- 对类前置声明和包含头文件的一点理解
- 关于 数据库表名为关键字 如 user。。
- (2012.05.21)端口大全
- usb转串口蓝屏问题的解决
- 实现C#打印窗体实例详解
- PB中TreeView控件使用技巧
- gridpanel动态重新加载columnModel与store
- 浅谈WebService开发三(动态调用WebService)
- C#实现图片打印
- x264编解码器 - Intel IPP
- Android Activity的四种LaunchMode!!!
- sql server
- 动态添加diV,实现了拖拽功能