C#控制BarTender自动打印(方法一)

最近公司规划了个新项目,要求自动打印贴纸,以达到提高生产效率及防呆防错的目的,经过研究琢磨终于实现;遂将代码与步骤整理出来,分享与大家

1.1 先使用BarTender创建btw档案,然后设置btw档案的内容与txt文件关联,这样修改txt文件的内容btw档案的内容就跟着变化

文章有新增内容,请各位小伙伴移步到这里:https://blog.csdn.net/caofuzhou/article/details/125943991

1.2 创建txt档案,档案内容为abc123,与btw档案同处于一个文件夹

1.3 btw档案内容关联txt档案内容 

 

 

跳过简单、繁琐的步骤,最后选择好栏位,点击“确定”完成关联设置

2.1 接下来是程式代码, 这里采用Win Form项目的方式实现自动打印

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;

namespace Example
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            string path = Application.StartupPath;
            string txt = path + "\\param.txt";//txt档案路径
            StreamWriter sw=new StreamWriter(txt,false);
            sw.WriteLine(textBox2.Text);

            string btw= path + "\\demo.btw";//btw档案路径
            Process p = null;
            //寻找名字为bartend的进程
            Process[] Po = Process.GetProcessesByName("bartend");
            if (Po.Length > 0)
            {
                p = Po[0];
                p.StartInfo.FileName = "bartend.exe";
                //列印btw档案并最小化程序
                p.StartInfo.Arguments = $@"/AF={btw} /P /min=SystemTray";
                p.EnableRaisingEvents = true;
            }
            else
            {
                p = new Process();
                p.StartInfo.FileName = "bartend.exe";
                p.StartInfo.Arguments = $@"/AF={btw} /P /min=SystemTray";
                p.EnableRaisingEvents = true;
            }
            //列印份数
            int pageCount = Convert.ToInt32(textBox2.Text);
            for (int i = 0; i < pageCount; i++)
            {
                p.Start();
            }
        }
    }
}

2.2 程式的界面,点击列印自动打印贴纸 

3.1 最后是打印机自动出贴纸 

 

  • 0
    点赞
  • 28
    收藏
    觉得还不错? 一键收藏
  • 7
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 7
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值