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

推荐订阅源

B
Blog RSS Feed
K
Kaspersky official blog
Forbes - Security
Forbes - Security
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
P
Proofpoint News Feed
G
GRAHAM CLULEY
V
Vulnerabilities – Threatpost
Security Latest
Security Latest
Scott Helme
Scott Helme
S
Securelist
美团技术团队
T
Threat Research - Cisco Blogs
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
S
SegmentFault 最新的问题
W
WeLiveSecurity
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
Apple Machine Learning Research
Apple Machine Learning Research
The Cloudflare Blog
AI
AI
L
Lohrmann on Cybersecurity
S
Security Affairs
Cloudbric
Cloudbric
SecWiki News
SecWiki News
爱范儿
爱范儿
雷峰网
雷峰网
Engineering at Meta
Engineering at Meta
C
Cyber Attacks, Cyber Crime and Cyber Security
大猫的无限游戏
大猫的无限游戏
N
News and Events Feed by Topic
I
InfoQ
S
Secure Thoughts
AWS News Blog
AWS News Blog
A
About on SuperTechFans
Schneier on Security
Schneier on Security
酷 壳 – CoolShell
酷 壳 – CoolShell
The Last Watchdog
The Last Watchdog
D
Darknet – Hacking Tools, Hacker News & Cyber Security
C
Check Point Blog
P
Palo Alto Networks Blog
博客园 - 【当耐特】
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
Google DeepMind News
Google DeepMind News
Latest news
Latest news
I
Intezer
博客园_首页
C
CXSECURITY Database RSS Feed - CXSecurity.com
V
V2EX
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
L
LangChain Blog
D
Docker

博客园 - 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(); }