C# print pos winform
先将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的更多相关文章
- pygame学习笔记
pygame参考文档pdf版:pygame API html版 pygame API 石头剪子布的简单小游戏,待改进的地方,自适应大小.感兴趣的小伙伴可以依据get_surface()返回值(即当前窗 ...
- 51. N-Queens
题目: The n-queens puzzle is the problem of placing n queens on an n×n chessboard such that no two que ...
- 【leetcode】Search for a Range
题目描述: Given a sorted array of integers, find the starting and ending position of a given target valu ...
- poj 1141 Brackets Sequence (区间dp)
题目链接:http://poj.org/problem?id=1141 题解:求已知子串最短的括号完备的全序列 代码: #include<iostream> #include<cst ...
- tornado 学习笔记7 RequestHandler功能分析
在第5部分讲到,构建一个tornado网站,必须包含一个或者多个handler,这些handler是RequestHandler的子类.每个请求都会被映射到handler中进行处理,处理 ...
- Reed-Solomon码,QR
原文: Reed–Solomon codes for coders参考: AN2407.pdfWIKI: 里德-所罗门码实现:Pypi ReedSolo #译注:最近看到了RS码,发现还挺有意思的,找 ...
- Deformity ASP/ASPX Webshell、Webshell Hidden Learning
catalog . Active Server Page(ASP) . ASP.NET . ASP WEBSHELL变形方式 . ASPX WEBSHELL变形方式 . webshell中常见的编码转 ...
- python生成中文验证码,带旋转,带干扰噪音线段
# -*- coding: utf-8 -*- """ Created on Sun Oct 4 15:57:46 2015 @author: keithguofan & ...
- RDLC直接打印帮助类
代码 /// <summary> /// 打印帮助类 /// </summary> public class PrintHelper { private int m_curre ...
随机推荐
- python 爬虫气象气象定时报 气象预警推送
"2018-04-09 14时""长沙市""10日(明天)""多云转雷阵雨""29℃""1 ...
- ES6系列_16之模块化操作
ES6的模块化操作主要包括两个方面. (1)export :负责进行模块化,也是模块的输出. (2)import : 负责把模块引,也是模块的引入操作. export的用法: export可以让我们把 ...
- JS: 如何计算一个月有多少天
转自:https://www.2cto.com/kf/201806/755776.html 1 function getCountDays() { var curDate = new Date(); ...
- Timer控件的使用限制和注意事项
Timer的Interval 属性当编写 Timer 组件时,需要考虑 Interval 属性的几点限制:1. 如果应用程序或另一个应用程序对系统需求很大(如长循环.大量的计算或驱动程序.网络或端口访 ...
- How to unlock Sample HR database in oracle
For working with tutorial of oracle Introduaction to oracle/sql you need to work on the tables which ...
- Yosemite 给 iOS 录屏
[Yosemite 给 iOS 录屏] Mac 升级到Yosemite后,支持iOS屏幕录制.把Mac和iPhone用数据线相连.打开QuickTime Player,新建一个影片. 从摄像头源中选择 ...
- 隐藏Android下的虚拟按键
要隐藏Android下的虚拟按键,可通过如下办法操作 adb root adb remount adb shell ls -al /system/build.prop (查看文件权限) -rw-r ...
- 聊一下Python的线程 & GIL
再来聊一下Python的线程 参考这篇文章 https://www.zhihu.com/question/23474039/answer/24695447 简单地说就是作为可能是仅有的支持多线程的解释 ...
- 79. Word Search (Array; DFS,Back-Track)
Given a 2D board and a word, find if the word exists in the grid. The word can be constructed from l ...
- jQuery的表单选择器
1.常规选择器选择表单标签 $(function () { // var a = $("input").eq(0).val() // alert(a) // // var b = ...