惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Latest news
Latest news
T
Troy Hunt's Blog
V
Vulnerabilities – Threatpost
L
LINUX DO - 热门话题
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
Simon Willison's Weblog
Simon Willison's Weblog
V
V2EX
博客园 - 司徒正美
B
Blog RSS Feed
AWS News Blog
AWS News Blog
MyScale Blog
MyScale Blog
Scott Helme
Scott Helme
Cisco Talos Blog
Cisco Talos Blog
Last Week in AI
Last Week in AI
NISL@THU
NISL@THU
博客园 - Franky
P
Proofpoint News Feed
博客园_首页
C
CERT Recently Published Vulnerability Notes
雷峰网
雷峰网
S
Schneier on Security
P
Proofpoint News Feed
Hugging Face - Blog
Hugging Face - Blog
G
GRAHAM CLULEY
博客园 - 三生石上(FineUI控件)
月光博客
月光博客
WordPress大学
WordPress大学
The Hacker News
The Hacker News
T
Threatpost
阮一峰的网络日志
阮一峰的网络日志
A
Arctic Wolf
Microsoft Azure Blog
Microsoft Azure Blog
T
The Exploit Database - CXSecurity.com
Engineering at Meta
Engineering at Meta
罗磊的独立博客
T
The Blog of Author Tim Ferriss
D
Darknet – Hacking Tools, Hacker News & Cyber Security
I
Intezer
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
K
Kaspersky official blog
SecWiki News
SecWiki News
云风的 BLOG
云风的 BLOG
美团技术团队
C
Cybersecurity and Infrastructure Security Agency CISA
博客园 - 【当耐特】
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
Security Latest
Security Latest
C
Cyber Attacks, Cyber Crime and Cyber Security
B
Blog
S
Security Affairs

博客园 - IT爱好者

C# 打印,不显示打印进度对话框 如何解决迅雷插件导致IE10崩溃的问题 ASP.NET MVC 使用Jquery Uploadify 在非IE浏览器下Http Error的解决方案 c#操作access,update语句不执行的解决办法 解决:System.Data.SqlClient.SqlError: FILESTREAM 功能被禁用 服务器“**”上的MSDTC不可用的解决办法 通过Package Manager Console 向VS2010安装 EFCodeFirst 删除SVN遗留的无用文件 解决"System.Data.OracleClient 需要 Oracle 客户端软件 8.1.7 或更高版本" 修改IIS默认的localhost名称 IIS服务器应用程序不可用的解决办法 使用XML与远程服务器进行交互 小米手机指令大全 Java与.NET DES加密解密互转 获取执行SQL语句的返回结果 ASP.NET中如何向页面写入JavaScript脚本内容 Oracle自增列创建方法 ASP.net中用JSON序列化对象 android Listview 拖动时背景为黑色问题
C# 自定义打印
IT爱好者 · 2013-03-11 · via 博客园 - IT爱好者

C# 自定义打印类,可以实现打印文本、线条、图片等,以下仅仅是举例代码:

public class PrintInfo
    {
        public string PortName { get; set; }
        public string DepartureTime { get; set; }
        public string AMPM { get; set; }

        PrintDocument document = new PrintDocument(); 
        private int pageWidth = 302;
        private int pageHeight = 530;

        public PrintInfo()
        {        
       PortName=“Test Port”;
       DepartureTime="11:30";
       AMPM="上午";       document.BeginPrint
+= new PrintEventHandler(document_BeginPrint); document.PrintPage += new PrintPageEventHandler(document_PrintPage); document.EndPrint += new PrintEventHandler(document_EndPrint); } private void document_EndPrint(object sender, PrintEventArgs e) { } private void document_BeginPrint(object sender, PrintEventArgs e) { } private void document_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e) { if (DepartureTime != null) { //Logo Bitmap imageLogo = new Bitmap(System.AppDomain.CurrentDomain.BaseDirectory + @"\Resource\logo.bmp"); e.Graphics.InterpolationMode = InterpolationMode.HighQualityBicubic; e.Graphics.SmoothingMode = SmoothingMode.HighQuality; e.Graphics.CompositingQuality = CompositingQuality.HighQuality; e.Graphics.DrawImage(imageLogo, 5, 10, 292, 131); //Line e.Graphics.DrawLine(new Pen(Brushes.Black, 3), 12, 166, 291, 166); //Port Name Font strFont = new Font("宋体", 18); e.Graphics.DrawString(PortName, strFont, Brushes.Black, (float)pageWidth / 2 - e.Graphics.MeasureString(PortName, strFont).Width / 2 + 1, 198); //Departure Time strFont = new Font("宋体", 50, FontStyle.Bold); e.Graphics.DrawString(DepartureTime, strFont, Brushes.Black, (float)pageWidth / 2 - e.Graphics.MeasureString(DepartureTime, strFont).Width / 2, 248); //AMPM e.Graphics.DrawString(AMPM, strFont, Brushes.Black, (float)pageWidth / 2 - e.Graphics.MeasureString(AMPM, strFont).Width / 2, 320); //Line e.Graphics.DrawLine(new Pen(Brushes.Black, 3), 12, 419, 291, 419); //Thankyou and print time strFont = new Font("宋体", 13, FontStyle.Bold); printTxt = "Thank You"; e.Graphics.DrawString(printTxt, strFont, Brushes.Black, 12, 481); strFont = new Font("宋体", 8); printTxt = DateTime.Now.ToString("MM/dd/yyyy hh:mmt\\M"); e.Graphics.DrawString(printTxt, strFont, Brushes.Black, 184, 487); } } public void PrintDocument() { document.DefaultPageSettings.PaperSize = new PaperSize("Custum", pageWidth, pageHeight); PrintController printController = new StandardPrintController(); document.PrintController = printController; //System.Windows.Forms.PrintPreviewDialog printPreview = new System.Windows.Forms.PrintPreviewDialog(); //printPreview.Document = document; //printPreview.ShowDialog(); document.Print(); }