All articles| All Pictures| All Softwares| All Video| Go home page| Write articles| Upload pictures

Reading number is top 10 articles
总结优化SQL Server数据库查询的方法_[SQL Server教程]
利用单元测试在每个层上对PHP代码进行检查_php资料_编程技术
GridView的各种用法(2)_[Asp.Net教程]
VS2005+SQL2005,ASP.NET2.0数据库连接_.net资料_编程技术
使用MD5加密注册用户密码的简单示例_.net资料_编程技术
XHTML 1.0:标记新的开端_[Html教程]
asp.net初学者项目开发疑难小结_[Asp.Net教程]
总结:表单复选框向PHP传输数据的研究_php资料_编程技术
增加网站流量方法之ASP.NET弹出窗口技术_.net资料_编程技术
PHP语言发展历史:它有三位创始人_php资料_编程技术
Reading number is top 10 pictures
The hot big eye big breast beauty1
The real super beauty3
Absolutely shocked. National geographic 50 animal photographys8
Sexy women in 2013--2
中国的阶级现状
乳娘帕梅拉安德森3
A man's favorite things9
移民小国也实惠2
人美胸美腿更美1
The little woman's bright wire1
Download software ranking
Tram sex maniac 2 (H) rar bag8
WebService在.NET中的实战应用教学视频 → 第3集
Call Of Duty2
网络管理员第三版
在线棋牌游戏3.05版
Popkart Cracked versions Mobile phone games
Unix video tutorial2
ASP.NET.2.0.XML.高级编程(第3版)
虚拟机汉化软件
Tram sex maniac 2 (H) rar bag17
qq published in(发表于) 2014/7/11 9:18:33 Edit(编辑)
C#中Windows打印对象的综合使用实例

C#中Windows打印对象的综合使用实例

C#中Windows打印对象的综合使用实例|方法

Windows打印对象的综合应用

下面通过一个综合实例来说明这5个对象的使用方法。

程序开发步骤如下所示。

(1)在VS2005中新建一个项目,并命名为PringTest。

(2)打开窗体设计器,从工具箱中将PageSetupDialog、PrintDialog、PrintDocument、

PrintPreviewControl和PrintPreviewDialog组件添加到窗体中,再添加一个Button按钮并将其Text属性改为“打印”,如图1所示。



图1 打印对象综合示例界面设计效果

(3)PrintPreviewControl1的Document属性设为printDocument1,在打印按钮的Click事件下并添加如下代码:

private void button1_Click(object sender, EventArgs e)

{

pageSetupDialog1.Document = printDocument1;

pageSetupDialog1.ShowDialog();

printPreviewControl1.Zoom = 0.75;

printPreviewDialog1.Document = this.printDocument1;

printPreviewDialog1.UseAntiAlias = True;

printPreviewDialog1.ShowDialog();

printDialog1.Document = printDocument1;

printDialog1.ShowDialog();

printDocument1.Print();

}

这段代码完成了打印设置的各个方面,其中printDocument1是连接各个对象的核心对象。

(4)选中printDialog1对象,单击鼠标右键在菜单中选择属性。为程序添加PrintPage事件并在事件的方法中添加如下代码:

private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)

{

Pen p = new Pen(Color.Black,5);

Point point1 = new Point(250, 350);

Point point2 = new Point(400, 425);

Point point3 = new Point(340, 525);

Point point4 = new Point(150, 550);

Point point5 = new Point(300, 1100);

Point[] curvePoints =

{

point1,

point2,

point3,

point4,

point5,

};

e.Graphics.FillRectangle(Brushes.Red, new Rectangle(150, 500, 500, 500));

e.Graphics.DrawPolygon(p, curvePoints);

e.Graphics.DrawString("打印测试!", new Font("Arial", 80, FontStyle.Bold), Brushes.Black, 150, 150);

}

printDocument1的Print()方法将引发PrintPage事件开始打印进程,PrintPageEventArgs对象的Graphics类用来绘制输出到屏幕或打印机的内容。程序运行结果如图2所示。



图2 打印对象运行效果

单击【打印】按钮,将弹出打印设置对话框如图3所示。

对打印页面进行设置,设置完毕后单击按钮,打印预览的效果如图4所示。

单击图4所示的打印机图标,将在打印机上打印预览到的图像。

通过这个简单的应用充分地说明了Windows打印对象的使用方法,和它们是怎样配合来完成整个打印过程的。在实际应用中主要扩展的部分就是Graphics类的使用,用它来画出各种文字和图形,从而完成复杂的打印。例如,做一套类似于水晶报表的报表设计器。



图3 打印设置对话框



图4 打印预览图

完整程序代码如下:

★ ★★★★Form1.cs窗体代码文件完整程序代码★★★★★

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Text;

using System.Windows.Forms;

namespace PrintTest

{

public partial class Form1 : Form

{

public Form1()

{

InitializeComponent();

}

private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)

{

try

{

Pen p = new Pen(Color.Black, 5);

Point point1 = new Point(150, 690);

Point point2 = new Point(650, 690);

Point point3 = new Point(400, 360);

Point point4 = new Point(150, 610);

 Point point5 = new Point(650, 610);

Point point6 = new Point(400, 280);

//Point point7 = new Point(250, 250);

Point[] curvePoints =

{

point1,

point2,

point3,



添加到del.icio.us 添加到新浪ViVi 添加到百度搜藏 添加到POCO网摘 添加到天天网摘365Key 添加到和讯网摘 添加到天极网摘 添加到黑米书签 添加到QQ书签 添加到雅虎收藏 添加到奇客发现 diigo it 添加到饭否 添加到飞豆订阅 添加到抓虾收藏 添加到鲜果订阅 digg it 貼到funP 添加到有道阅读 Live Favorites 添加到Newsvine 打印本页 用Email发送本页 在Facebook上分享


Disclaimer Privacy Policy About us Site Map

If you have any requirements, please contact webmaster。(如果有什么要求,请联系站长)
Copyright ©2011-
uuhomepage.com, Inc. All rights reserved.