//----  program.cs

using System;
using System.Collections.Generic;
using System.Windows.Forms;

using System.Runtime.InteropServices;
public class TSCLIB_DLL
{
 [DllImport("TSCLIB.dll", EntryPoint = "about")]
    public static extern int about();

[DllImport("TSCLIB.dll", EntryPoint = "openport")]
    public static extern int openport(string printername);

[DllImport("TSCLIB.dll", EntryPoint = "barcode")]
    public static extern int barcode(string x, string y, string type,
                string height, string readable, string rotation,
                string narrow, string wide, string code);

[DllImport("TSCLIB.dll", EntryPoint = "clearbuffer")]
    public static extern int clearbuffer();

[DllImport("TSCLIB.dll", EntryPoint = "closeport")]
    public static extern int closeport();

[DllImport("TSCLIB.dll", EntryPoint = "downloadpcx")]
    public static extern int downloadpcx(string filename, string image_name);

[DllImport("TSCLIB.dll", EntryPoint = "formfeed")]
    public static extern int formfeed();

[DllImport("TSCLIB.dll", EntryPoint = "nobackfeed")]
    public static extern int nobackfeed();

[DllImport("TSCLIB.dll", EntryPoint = "printerfont")]
    public static extern int printerfont(string x, string y, string fonttype,
                    string rotation, string xmul, string ymul,
                    string text);

[DllImport("TSCLIB.dll", EntryPoint = "printlabel")]
    public static extern int printlabel(string set, string copy);

[DllImport("TSCLIB.dll", EntryPoint = "sendcommand")]
    public static extern int sendcommand(string printercommand);

[DllImport("TSCLIB.dll", EntryPoint = "setup")]
    public static extern int setup(string width, string height,
              string speed, string density,
              string sensor, string vertical,
              string offset);

[DllImport("TSCLIB.dll", EntryPoint = "windowsfont")]
    public static extern int windowsfont(int x, int y, int fontheight,
     int rotation,  int fontstyle, int fontunderline,
                    string szFaceName, string content);
  
}

namespace TSCLIB_DLL_IN_C_Sharp
{
    static class Program
    {
        /// <summary>
        /// 應用程式的主要進入點。
        /// </summary>
        [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new Form1());
        }
    }
}

//----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 TSCLIB_DLL_IN_C_Sharp
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

private void button1_Click(object sender, EventArgs e)
        {
            //TSCLIB_DLL.about();                                                                //Show the DLL version
            TSCLIB_DLL.openport("TSC TTP-344M Plus");                                          //Open specified printer driver
            TSCLIB_DLL.setup("100", "63.5", "4", "8", "0", "0", "0");                          //Setup the media size and sensor type info
            TSCLIB_DLL.clearbuffer();                                                          //Clear image buffer
            TSCLIB_DLL.barcode("100", "100", "128", "100", "1", "0", "2", "2", "Barcode Test"); //Drawing barcode
            TSCLIB_DLL.printerfont("100", "250", "3", "0", "1", "1", "Print Font Test");       //Drawing printer font
            TSCLIB_DLL.windowsfont(100, 300, 24, 0, 0, 0, "ARIAL", "Windows Arial Font Test"); //Draw windows font
            TSCLIB_DLL.downloadpcx("UL.PCX", "UL.PCX");                                        //Download PCX file into printer
            TSCLIB_DLL.sendcommand("PUTPCX 100,400,"UL.PCX"");                               //Drawing PCX graphic
            TSCLIB_DLL.printlabel("1", "1");                                                   //Print labels
            TSCLIB_DLL.closeport();                                                            //Close specified printer driver
           
        }
    }
}

//------ 另例

[System.Runtime.InteropServices.DllImport("tsclib.dll")]
  private static extern void windowsfont(int a, int b, int c,int d,int e ,int f, string g ,string h);
  [System.Runtime.InteropServices.DllImport("tsclib.dll")]
  private static extern void openport(string printername);
  [System.Runtime.InteropServices.DllImport("tsclib.dll")]
  private static extern void closeport();
  [System.Runtime.InteropServices.DllImport("tsclib.dll")]
  private static extern void sendcommand(string command);
  [System.Runtime.InteropServices.DllImport("tsclib.dll")]
  private static extern void setup(string width,string height,string speed,string density,string sensor,string vertical,string offset);
  [System.Runtime.InteropServices.DllImport("tsclib.dll")]
  private static extern void clearbuffer();
  [System.Runtime.InteropServices.DllImport("tsclib.dll")]
  private static extern void printlabel(string Set,string Copy);

private void button1_Click(object sender, System.EventArgs e)
  {
   openport("TSC TTP-343");
   setup("100","65","3","10","0","3","0");
   clearbuffer();
   windowsfont(50,30,70,0,0,0,"黑体","索书号:");
   printlabel("1", "1");
   closeport();
  }

#region 调用TSC打印机打印条码
        /// <summary>
        /// 调用TSC打印机打印条码
        /// </summary>
        /// <param name="title">打印的标题</param>
        /// <param name="barCode">打印的条码编号</param>
        public static void TSC(string title, string barCode)
        {
            // 打开 打印机 端口.
            TSCLIB_DLL.openport(p_port);
            // 设置标签 宽度、高度 等信息.
            // 宽 94mm  高 25mm
            // 速度为4
            // 字体浓度为8
            // 使用垂直間距感測器(gap sensor)
            // 两个标签之间的  间距为 3.5mm
            TSCLIB_DLL.setup("94", "25", "4", "8", "0", "3.5", "0");
            // 清除缓冲信息
            TSCLIB_DLL.clearbuffer();
            // 发送 TSPL 指令.
            // 设置 打印的方向.
            TSCLIB_DLL.sendcommand("DIRECTION 1");
            // 打印文本信息.
            // 在 (176, 16) 的坐标上
            // 字体高度为34
            // 旋转的角度为 0 度
            // 2 表示 粗体.
            // 文字没有下划线.
            // 字体为 黑体.
            // 打印的内容为:title
            TSCLIB_DLL.windowsfont(176, 16, 34, 0, 2, 0, "宋体", title);
            // 打印条码.
            // 在 (176, 66) 的坐标上
            // 以 Code39 的条码方式
            // 条码高度 130
            // 打印条码的同时,还打印条码的文本信息.
            // 旋转的角度为 0 度
            // 条码 宽 窄 比例因子为 7:12
            // 条码内容为:barCode
            TSCLIB_DLL.barcode("176", "66", "39", "130", "1", "0", "7", "12", barCode);
            // 打印.
            TSCLIB_DLL.printlabel("1", "1");
            // 关闭 打印机 端口
            TSCLIB_DLL.closeport();
        }
#endregion

TSC条码打印机C#例程(tsclib.dll调用) 【转】的更多相关文章

  1. TSC条码打印机C#例程(tsclib.dll调用)

    TSC条码打印机C#例程(tsclib.dll调用) //----  program.cs using System;using System.Collections.Generic;using Sy ...

  2. DLL放在指定目录 以及设置dll调用路径

    一.DLL放在指定目录 在编写C# winform程序中,不免一个项目会有多个工程文件,而这些工程文件之间是相互引用的,所以不想将工程的生成结果(exe或者dll)放在当前工程bin目录下的Debug ...

  3. zw版【转发·台湾nvp系列Delphi例程】.NET调用HALCON COM控件内存释放模式

    zw版[转发·台湾nvp系列Delphi例程].NET调用HALCON COM控件内存释放模式 ------------------------------------方法一 :Imports Sys ...

  4. opencv通过dll调用matlab函数,图片作为参数

    [blog 项目实战派]opencv通过dll调用matlab函数,图片作为参数                   前文介绍了如何“csharp通过dll调用opencv函数,图片作为参数”.而在实 ...

  5. csharp通过dll调用opencv函数,图片作为参数

    [blog 项目实战派]csharp通过dll调用opencv函数,图片作为参数          ​一直想做着方面的研究,但是因为这个方面的知识过于小众,也是由于自己找资料的能力比较弱,知道今天才找 ...

  6. C++ dll调用-动态(显式)

    C++ dll调用-动态(显式) 废话不说上代码, dll 头文件 j_test.h #pragma once extern "C"_declspec(dllexport) voi ...

  7. DLL调用的两种方式(IDE:VC6.0,C++)

    原文:http://www.cnblogs.com/Pickuper/articles/2050409.html DLL调用有两种方式,一种是静态调用,另外一种是动态调用 (一)静态调用 静态调用是一 ...

  8. C++ 多项目dll调用-隐式

    将DAA人脸检测做成动态库以便其他程序调用,采用隐式调用完成. 给出部分关于dll制作的关键代码: 1.DLL 多项目DLL编写注意将其他相关项目设置成静态库,以及各库涉及的版本一致性. DLL.h ...

  9. delphi 跨版本DLL调用嵌入窗体实现

    delphi 能实现把别的DLL的窗体句柄查到后,贴到PANL之中,此类文章网上不少,而如果是delphi不同版本开发的DLL互调时,一些控件内部的定义有所区别,因为无法(至少目前我觉得理论上不可行) ...

随机推荐

  1. Java基础练习4(内存管理)

    请根据如下程序代码,画出对应的内存管理图(不需要画方法区),并写出输出结果. 1. public class Cell{ int row; int col; public Cell(int row,i ...

  2. JQuery --- 第一期 (初识jQuery, JQuery核心函数和工具方法)

    个人学习笔记  初识jQuery 1.我的第一个JQuery <!DOCTYPE html> <html lang="en"> <head> & ...

  3. Android resource compilation failed

    报错:Android resource compilation failed D:\android\EasySports\app\build\intermediates\incremental\mer ...

  4. Vagrant 构建 Linux 开发环境

    Vagrant 是一个简单易用的部署工具,用英文说应该是 Orchestration Tool .它能帮助开发人员迅速的构建一个开发环境,帮助测试人员构建测试环境, Vagrant 基于 Ruby 开 ...

  5. The Network Adapter could not establish the connection

    启动即可

  6. 第二章.python入门

    2.1环境的安装 解释器:py2和py3 添加环境变量的作用:便于找到python解释器 开发工具:pycharm 2.2编码 2.2.1编码基础 ascii:只表示英文,8位表示一个元素,pytho ...

  7. chrome谷歌开发者工具(hover时候的css样式怎么在浏览器调试)

    很多小伙伴在开发的时候,大多是在用谷歌开发者工具调试代码(快捷键F12 或 Ctrl-Shift-i). 可能会经常遇到需要调试hover样式的时候,一般都是直接改代码,然后在页面上刷新查看效果. 其 ...

  8. 常见形式 Web API 的简单分类总结

    一.请求--响应API. 请求--响应类的API的典型做法是,通过基于HTTP的Web服务器暴露一个/套接口.API定义一些端点,客户端发送数据的请求到这些端点,Web服务器处理这些请求,然后返回响应 ...

  9. 《深入理解Java虚拟机》-----第5章 jvm调优案例分析与实战

    案例分析 高性能硬件上的程序部署策略 例 如 ,一个15万PV/天左右的在线文档类型网站最近更换了硬件系统,新的硬件为4个CPU.16GB物理内存,操作系统为64位CentOS 5.4 , Resin ...

  10. 痞子衡嵌入式:恩智浦i.MXRT系列微控制器量产神器RT-Flash用户指南

    RT Flash English | 中文 1 软件概览 1.1 介绍 RT-Flash是一个专为基于NXP i.MX RT系列芯片的产品量产而设计的工具,其功能与官方MfgTool2工具类似,但是解 ...