先将pos机设置为默认

控制面板->打印机和传真->右键->服务器属性

首先创建 ClassPrint 对象

using System;
using System.Drawing;
using System.Drawing.Printing;
using System.IO;
using System.Text; namespace PrintWinform
{
class ClassPrint
{
//定义一个字符串流,用来接收所要打印的数据
private static StringReader sr;
//str要打印的数据
public static bool Print(StringBuilder str)
{
bool result = true;
try
{
sr = new StringReader(str.ToString());
PrintDocument pd = new PrintDocument();
pd.PrintController = new System.Drawing.Printing.StandardPrintController();
//pd.DefaultPageSettings.Margins.Top = 2;
//pd.DefaultPageSettings.Margins.Left = 0;
//pd.DefaultPageSettings.PaperSize.Width = 320;
pd.DefaultPageSettings.Margins = new Margins(, , , ); //pd.DefaultPageSettings.PaperSize.Height = 5150;
pd.PrinterSettings.PrinterName = pd.DefaultPageSettings.PrinterSettings.PrinterName;//默认打印机
pd.PrintPage += new PrintPageEventHandler(pd_PrintPage);
pd.Print();
}
catch (Exception ex)
{
result = false;
}
finally
{
if (sr != null)
sr.Close();
}
return result;
} private static void pd_PrintPage(object sender, PrintPageEventArgs ev)
{
Font printFont = new Font("Arial", );//打印字体
float linesPerPage = ;
float yPos = ;
int count = ;
float leftMargin = ev.MarginBounds.Left;
float topMargin = ev.MarginBounds.Top;
String line = string.Empty;
linesPerPage = ev.MarginBounds.Height / printFont.GetHeight(ev.Graphics);
while (count < linesPerPage && ((line = sr.ReadLine()) != null))
{
yPos = topMargin + (count * printFont.GetHeight(ev.Graphics));
ev.Graphics.DrawString(line, printFont, Brushes.Black,
leftMargin, yPos, new StringFormat());
count++;
}
// If more lines exist, print another page.
if (line != null)
ev.HasMorePages = true;
else
ev.HasMorePages = false;
}
}
}

然后UI form

    private void button1_Click(object sender, EventArgs e)
{
StringBuilder sb = new StringBuilder();
sb.Append(" 心理测评一体机 \n");
sb.Append(" 职业倾向人格临床量表 \n");
sb.Append("***********************************************\n");
sb.Append("E量表得分为:32分,您的性格内向\n");
sb.Append("N量表得分为:28分,您的情绪稳定性高\n");
sb.Append("P量表得分为:56分,您的倔强性一般\n");
sb.Append("L量表得分为:51分,您的掩饰性一般。\n");
sb.Append("***********************************************\n");
sb.Append(" 北京XXXX科技有限公司\n");
sb.Append(" 测评结果仅供参考,最终结果请以心理咨询师为准\n");
ClassPrint.Print(sb);
}

C# print pos winform的更多相关文章

  1. pygame学习笔记

    pygame参考文档pdf版:pygame API html版 pygame API 石头剪子布的简单小游戏,待改进的地方,自适应大小.感兴趣的小伙伴可以依据get_surface()返回值(即当前窗 ...

  2. 51. N-Queens

    题目: The n-queens puzzle is the problem of placing n queens on an n×n chessboard such that no two que ...

  3. 【leetcode】Search for a Range

    题目描述: Given a sorted array of integers, find the starting and ending position of a given target valu ...

  4. poj 1141 Brackets Sequence (区间dp)

    题目链接:http://poj.org/problem?id=1141 题解:求已知子串最短的括号完备的全序列 代码: #include<iostream> #include<cst ...

  5. tornado 学习笔记7 RequestHandler功能分析

           在第5部分讲到,构建一个tornado网站,必须包含一个或者多个handler,这些handler是RequestHandler的子类.每个请求都会被映射到handler中进行处理,处理 ...

  6. Reed-Solomon码,QR

    原文: Reed–Solomon codes for coders参考: AN2407.pdfWIKI: 里德-所罗门码实现:Pypi ReedSolo #译注:最近看到了RS码,发现还挺有意思的,找 ...

  7. Deformity ASP/ASPX Webshell、Webshell Hidden Learning

    catalog . Active Server Page(ASP) . ASP.NET . ASP WEBSHELL变形方式 . ASPX WEBSHELL变形方式 . webshell中常见的编码转 ...

  8. python生成中文验证码,带旋转,带干扰噪音线段

    # -*- coding: utf-8 -*- """ Created on Sun Oct 4 15:57:46 2015 @author: keithguofan & ...

  9. RDLC直接打印帮助类

    代码 /// <summary> /// 打印帮助类 /// </summary> public class PrintHelper { private int m_curre ...

随机推荐

  1. python之解析csv

    使用csv包 读取信息 csvfile = file('csv_test.csv', 'rb') reader = csv.reader(csvfile) for line in reader: pr ...

  2. JDK常用命令

    转自:https://www.cnblogs.com/saiQsai/p/10353044.html 1.jps 查看java进程,得到进程ID:7854 作用等同于:ps -ef | grep ja ...

  3. Mysql 索引优化 - 1

    单表  范围查询 后面的索引会失效 双表  左右连接建立索引互相使用 三表   用小结果集驱动大表结果, 先优化括号里面的SQL, 保证JOIN被驱动的表上ON字段有索引 索引失效(常见原因) 全职匹 ...

  4. javascript常用验证大全

    1. 长度限制 <script> function test() { if(document.a.b.value.length>50) { alert("不能超过50个字符 ...

  5. Git----远程仓库01

    到目前为止,我们已经掌握了如何在Git仓库里对一个文件进行时光穿梭,你再也不用担心文件备份或者丢失的问题了 可是用过集中式版本控制系统SVN的童鞋们会站出来说,这些功能在SVN里早就有了,没看出Git ...

  6. 迷你MVVM框架 avalonjs 0.97发布

    在本版本中,王之三柱臣全部就位! mmRouter: https://github.com/RubyLouvre/mmRouter mmAnimate: https://github.com/Ruby ...

  7. UIview需要知道的一些事情:setNeedsDisplay、setNeedsLayout

    UIview需要知道的一些事情:setNeedsDisplay.setNeedsLayout 1.在Mac OS中NSWindow的父类是NSResponder,而在i OS 中UIWindow 的父 ...

  8. InfoPanel

    [InfoPanel] The Info panel shows the color values beneath the pointer and, depending on the tool in ...

  9. awk使用

    [awk使用] 例:awk -F ':' '{print $1"\t"$7}' 参考:http://www.cnblogs.com/ggjucheng/archive/2013/0 ...

  10. SpringAop及拦截器

    一.Aop Aop,面向切面编程,提供了一种机制,在执行业务前后执行另外的代码. 切面编程包括切面(Aspect),连接点(Joinpoint).通知(Advice).切入点(Pointcut).引入 ...