相对于图形打印,codesoft算是一种简单易行的方法。

1,codesoft7下载安装

下载地址: https://download.csdn.net/download/sknwsknw/10713559
下载地址二: https://download.csdn.net/download/qq_37326058/11265990
下载,安装,替换文件,破解成功。 注意这时候 在 c:/Program Files / 会生成两个文件夹,codesoft7 和 Tki 文件夹。

2,条码设计保存

codesoft图文教程: https://wenku.baidu.com/view/7825d13104a1b0717ed5dd9c.html

任意变量的设置,打印机的设置,尺寸的设置等等吧.(打印机设置很重要啊) ,制作完成,命名为barJapLab.lab,放在c#程序根目录下。

如下,点击打印机图标,点击添加,就可以添加对应打印机的驱动了。(DPI:像素点数,DPI越高,打印精度越高)

3,c#代码设计

codesoft官网c#代码示例:https://www.codesoft.hk/archives/6559
c#,vb调用codesoft :https://blog.csdn.net/lv_fu/article/details/51702257

程序下载地址:https://download.csdn.net/download/qq_37326058/11266043

参照codesoft官网 教程,引用dll。

1,visual studio 中,添加引用>com>浏览> 在 C:\Program Files\Tki\7\Common 中搜索 Lppx2.tlb,点击添加,引用中会出现labelmanager2.dll的引用(注意了,要右键 labelmanager2.dll,嵌入互操作类型设置为false)



2, vs 中创建 BaseForm基类(作用就是让窗体控件随窗体大小等比例变化),代码如下:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;namespace WindowsFormsApplication2
{public partial class BaseForm : Form{public BaseForm(){InitializeComponent();}private float X;//当前窗体的宽度private float Y;//当前窗体的高度/// <summary>/// 将控件的宽,高,左边距,顶边距和字体大小暂存到tag属性中/// </summary>/// <param name="cons">递归控件中的控件</param>private void setTag(Control cons){foreach (Control con in cons.Controls){con.Tag = con.Width + ":" + con.Height + ":" + con.Left + ":" + con.Top + ":" + con.Font.Size;if (con.Controls.Count > 0)setTag(con);}}//根据窗体大小调整控件大小private void setControls(float newx, float newy, Control cons){//遍历窗体中的控件,重新设置控件的值foreach (Control con in cons.Controls){string[] mytag = con.Tag.ToString().Split(new char[] { ':' });//获取控件的Tag属性值,并分割后存储字符串数组float a = System.Convert.ToSingle(mytag[0]) * newx;//根据窗体缩放比例确定控件的值,宽度con.Width = (int)a;//宽度a = System.Convert.ToSingle(mytag[1]) * newy;//高度con.Height = (int)(a);a = System.Convert.ToSingle(mytag[2]) * newx;//左边距离con.Left = (int)(a);a = System.Convert.ToSingle(mytag[3]) * newy;//上边缘距离con.Top = (int)(a);Single currentSize = System.Convert.ToSingle(mytag[4]) * newy;//字体大小con.Font = new Font(con.Font.Name, currentSize, con.Font.Style, con.Font.Unit);if (con.Controls.Count > 0){setControls(newx, newy, con);}}}//private void BaseForm_Load(object sender, EventArgs e)//{//    X = this.Width;//获取窗体的宽度//    Y = this.Height;//获取窗体的高度//    setTag(this);//调用方法//}private void BaseForm_Resize(object sender, EventArgs e){float newx = (this.Width) / X; //窗体宽度缩放比例float newy = (this.Height) / Y;//窗体高度缩放比例setControls(newx, newy, this);//随窗体改变控件大小}protected override void OnLoad(EventArgs e){base.OnLoad(e);this.Resize += new EventHandler(BaseForm_Resize);X = this.Width;Y = this.Height;setTag(this);}}
}

3,创建打印条码的窗体Form2, progressBar控件命名为 progressBar1,richtextbox控件命名为 lbStatus,button控件命名为 buttonX1,dataGridView控件命名为 dataGridView1。

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;namespace WindowsFormsApplication2
{public partial class Form2 : BaseForm {public int ilableLx = 0 ;//打印模板类型,目前这里仅一个模板//public DataGridView dv;//定义公共变量,调用这个窗口时把datagridview传进来,public Form2(){InitializeComponent();InitializeDataGridView();}//barcode_noprivate System.Windows.Forms.DataGridViewTextBoxColumn barcode_no;//style_noprivate System.Windows.Forms.DataGridViewTextBoxColumn style_no;//upp_jpprivate System.Windows.Forms.DataGridViewTextBoxColumn upp_jp;//outsole_jpprivate System.Windows.Forms.DataGridViewTextBoxColumn outsole_jp;//col_jpprivate System.Windows.Forms.DataGridViewTextBoxColumn col_jp;//size_widthprivate System.Windows.Forms.DataGridViewTextBoxColumn size_width;//priceprivate System.Windows.Forms.DataGridViewTextBoxColumn price;//comp_jpprivate System.Windows.Forms.DataGridViewTextBoxColumn comp_jp;//address_jpprivate System.Windows.Forms.DataGridViewTextBoxColumn address_jp;//urlprivate System.Windows.Forms.DataGridViewTextBoxColumn url;//qtyprivate System.Windows.Forms.DataGridViewTextBoxColumn qty;public void InitializeDataGridView(){//barcode_nothis.barcode_no = new System.Windows.Forms.DataGridViewTextBoxColumn();this.dataGridView1.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {this.barcode_no});this.barcode_no.HeaderText = "barcode_no";this.barcode_no.Name = "barcode_no";//style_nothis.style_no = new System.Windows.Forms.DataGridViewTextBoxColumn();this.dataGridView1.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {this.style_no});this.style_no.HeaderText = "style_no";this.style_no.Name = "style_no";//upp_jpthis.upp_jp = new System.Windows.Forms.DataGridViewTextBoxColumn();this.dataGridView1.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {this.upp_jp});this.upp_jp.HeaderText = "upp_jp";this.upp_jp.Name = "upp_jp";//outsole_jpthis.outsole_jp = new System.Windows.Forms.DataGridViewTextBoxColumn();this.dataGridView1.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {this.outsole_jp});this.outsole_jp.HeaderText = "outsole_jp";this.outsole_jp.Name = "outsole_jp";//col_jpthis.col_jp = new System.Windows.Forms.DataGridViewTextBoxColumn();this.dataGridView1.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {this.col_jp});this.col_jp.HeaderText = "col_jp";this.col_jp.Name = "col_jp";//size_widththis.size_width = new System.Windows.Forms.DataGridViewTextBoxColumn();this.dataGridView1.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {this.size_width});this.size_width.HeaderText = "size_width";this.size_width.Name = "size_width";//pricethis.price = new System.Windows.Forms.DataGridViewTextBoxColumn();this.dataGridView1.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {this.price});this.price.HeaderText = "price";this.price.Name = "price";//comp_jpthis.comp_jp = new System.Windows.Forms.DataGridViewTextBoxColumn();this.dataGridView1.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {this.comp_jp});this.comp_jp.HeaderText = "comp_jp";this.comp_jp.Name = "comp_jp";//address_jpthis.address_jp = new System.Windows.Forms.DataGridViewTextBoxColumn();this.dataGridView1.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {this.address_jp});this.address_jp.HeaderText = "address_jp";this.address_jp.Name = "address_jp";//urlthis.url = new System.Windows.Forms.DataGridViewTextBoxColumn();this.dataGridView1.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {this.url});this.url.HeaderText = "url";this.url.Name = "url";//qtythis.qty = new System.Windows.Forms.DataGridViewTextBoxColumn();this.dataGridView1.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {this.qty});this.qty.HeaderText = "qty";this.qty.Name = "qty";dataGridView1.Columns[0].HeaderText = "barcode_no";dataGridView1.Columns[1].HeaderText = "style_no";dataGridView1.Columns[2].HeaderText = "upp_jp";dataGridView1.Columns[3].HeaderText = "outsole_jp";dataGridView1.Columns[4].HeaderText = "col_jp";dataGridView1.Columns[5].HeaderText = "size_width";dataGridView1.Columns[6].HeaderText = "price";dataGridView1.Columns[7].HeaderText = "comp_jp";dataGridView1.Columns[8].HeaderText = "address_jp";dataGridView1.Columns[9].HeaderText = "url";dataGridView1.Columns[10].HeaderText = "qty";this.dataGridView1.Rows.Add();this.dataGridView1.Rows[0].Cells[0].Value = "1";this.dataGridView1.Rows[0].Cells[1].Value = "Baqar";this.dataGridView1.Rows[0].Cells[2].Value = "1";this.dataGridView1.Rows[0].Cells[3].Value = "Baqar";this.dataGridView1.Rows[0].Cells[4].Value = "1";this.dataGridView1.Rows[0].Cells[5].Value = "Baqar";this.dataGridView1.Rows[0].Cells[6].Value = "1";this.dataGridView1.Rows[0].Cells[7].Value = "Baqar";this.dataGridView1.Rows[0].Cells[8].Value = "1";this.dataGridView1.Rows[0].Cells[9].Value = "Baqar";this.dataGridView1.Rows[0].Cells[10].Value = "1";this.dataGridView1.Rows.Add();this.dataGridView1.Rows[1].Cells[0].Value = "2";this.dataGridView1.Rows[1].Cells[1].Value = "Baqar";this.dataGridView1.Rows[1].Cells[2].Value = "1";this.dataGridView1.Rows[1].Cells[3].Value = "Baqar";this.dataGridView1.Rows[1].Cells[4].Value = "1";this.dataGridView1.Rows[1].Cells[5].Value = "Baqar";this.dataGridView1.Rows[1].Cells[6].Value = "1";this.dataGridView1.Rows[1].Cells[7].Value = "Baqar";this.dataGridView1.Rows[1].Cells[8].Value = "1";this.dataGridView1.Rows[1].Cells[9].Value = "Baqar";this.dataGridView1.Rows[1].Cells[10].Value = "1";this.dataGridView1.Rows.Add();this.dataGridView1.Rows[2].Cells[0].Value = "3";this.dataGridView1.Rows[2].Cells[1].Value = "Baqar";this.dataGridView1.Rows[2].Cells[2].Value = "1";this.dataGridView1.Rows[2].Cells[3].Value = "Baqar";this.dataGridView1.Rows[2].Cells[4].Value = "1";this.dataGridView1.Rows[2].Cells[5].Value = "Baqar";this.dataGridView1.Rows[2].Cells[6].Value = "1";this.dataGridView1.Rows[2].Cells[7].Value = "Baqar";this.dataGridView1.Rows[2].Cells[8].Value = "1";this.dataGridView1.Rows[2].Cells[9].Value = "Baqar";this.dataGridView1.Rows[2].Cells[10].Value = "1";}protected override bool ProcessCmdKey(ref Message msg, Keys keyData){if (keyData == Keys.Escape){Close();}else if (keyData == Keys.Enter){SendKeys.Send("{tab}");return true;}return base.ProcessCmdKey(ref msg, keyData);}private void btnSet_Click(object sender, EventArgs e){}private void btnPrint_Click(object sender, EventArgs e){if (ilableLx == 0)//模板一{LabelManager2.ApplicationClass labApp = null;LabelManager2.Document doc = null;string labFileName = System.Windows.Forms.Application.StartupPath + @"\barJapLab.Lab";//try//{if (!File.Exists(labFileName)){MessageBox.Show("沒有找到標簽模板文件:barJapLab.Lab,請聯系系統管理員", "溫馨提示");return;}labApp = new LabelManager2.ApplicationClass();labApp.Documents.Open(labFileName, false);// 调用设计好的label文件doc = labApp.ActiveDocument;if (dataGridView1.SelectedRows.Count > 0){progressBar1.Maximum = dataGridView1.SelectedRows.Count;progressBar1.Value = 0;for (int i = 0; i < dataGridView1.SelectedRows.Count; i++) //选中多行打印{//下面这些是给模板的变量传值进去doc.Variables.FormVariables.Item("barcode_no").Value = dataGridView1.SelectedRows[i].Cells["barcode_no"].Value.ToString();doc.Variables.FormVariables.Item("style_no").Value = dataGridView1.SelectedRows[i].Cells["style_no"].Value.ToString();doc.Variables.FormVariables.Item("upp_jp").Value = dataGridView1.SelectedRows[i].Cells["upp_jp"].Value.ToString();doc.Variables.FormVariables.Item("outsole_jp").Value = dataGridView1.SelectedRows[i].Cells["outsole_jp"].Value.ToString();doc.Variables.FormVariables.Item("col_jp").Value = dataGridView1.SelectedRows[i].Cells["col_jp"].Value.ToString();doc.Variables.FormVariables.Item("size_width").Value = dataGridView1.SelectedRows[i].Cells["size_width"].Value.ToString();doc.Variables.FormVariables.Item("price").Value = dataGridView1.SelectedRows[i].Cells["price"].Value.ToString();doc.Variables.FormVariables.Item("comp_jp").Value = dataGridView1.SelectedRows[i].Cells["comp_jp"].Value.ToString();doc.Variables.FormVariables.Item("address_jp").Value = dataGridView1.SelectedRows[i].Cells["address_jp"].Value.ToString();doc.Variables.FormVariables.Item("url").Value = dataGridView1.SelectedRows[i].Cells["url"].Value.ToString();//下面这行是打印份数的定义doc.PrintDocument(Convert.ToInt16(dataGridView1.SelectedRows[i].Cells["qty"].Value)); //+ Convert.ToInt16(dataGridView1.SelectedRows[i].Cells["att_qty"].Value));progressBar1.Value++;progressBar1.Refresh();lbStatus.Text = "總共" + dataGridView1.SelectedRows.Count.ToString() + "行需要列印,已送出" + Convert.ToString(i + 1) + "行";lbStatus.Refresh();this.Refresh();}}else //光标所在行打印{//doc.Variables.FormVariables.Item("barcode_no").Value = dv.CurrentRow.Cells["barcode_no"].Value.ToString();//doc.Variables.FormVariables.Item("style_no").Value = dv.CurrentRow.Cells["style_no"].Value.ToString();//doc.Variables.FormVariables.Item("upp_jp").Value = dv.CurrentRow.Cells["upp_jp"].Value.ToString();//doc.Variables.FormVariables.Item("outsole_jp").Value = dv.CurrentRow.Cells["outsole_jp"].Value.ToString();//doc.Variables.FormVariables.Item("col_jp").Value = dv.CurrentRow.Cells["col_jp"].Value.ToString();//doc.Variables.FormVariables.Item("size_width").Value = dv.CurrentRow.Cells["size_width"].Value.ToString();//doc.Variables.FormVariables.Item("price").Value = dv.CurrentRow.Cells["price"].Value.ToString();//doc.Variables.FormVariables.Item("comp_jp").Value = dv.CurrentRow.Cells["comp_jp"].Value.ToString();//doc.Variables.FormVariables.Item("address_jp").Value = dv.CurrentRow.Cells["address_jp"].Value.ToString();//doc.Variables.FormVariables.Item("url").Value = dv.CurrentRow.Cells["url"].Value.ToString();//doc.PrintDocument(Convert.ToInt16(dv.CurrentRow.Cells["qty"].Value));doc.Variables.FreeVariables.Item("变量0").Value = dataGridView1.CurrentRow.Cells["barcode_no"].Value.ToString();doc.Variables.FreeVariables.Item("变量1").Value = dataGridView1.CurrentRow.Cells["style_no"].Value.ToString();doc.Variables.FreeVariables.Item("变量2").Value = dataGridView1.CurrentRow.Cells["upp_jp"].Value.ToString();doc.Variables.FreeVariables.Item("变量3").Value = dataGridView1.CurrentRow.Cells["outsole_jp"].Value.ToString();doc.Variables.FreeVariables.Item("变量4").Value = dataGridView1.CurrentRow.Cells["col_jp"].Value.ToString();doc.Variables.FreeVariables.Item("变量5").Value = dataGridView1.CurrentRow.Cells["size_width"].Value.ToString();doc.Variables.FreeVariables.Item("变量6").Value = dataGridView1.CurrentRow.Cells["price"].Value.ToString();doc.Variables.FreeVariables.Item("变量8").Value = dataGridView1.CurrentRow.Cells["comp_jp"].Value.ToString();doc.Variables.FreeVariables.Item("变量9").Value = dataGridView1.CurrentRow.Cells["address_jp"].Value.ToString();doc.Variables.FreeVariables.Item("变量10").Value = dataGridView1.CurrentRow.Cells["url"].Value.ToString();doc.PrintDocument(Convert.ToInt16(dataGridView1.CurrentRow.Cells["qty"].Value));}//}//catch (Exception ex)//{//    MessageBox.Show("出錯啦,原因如下:\n\r" + ex.Message, "出錯啦");//}//finally//{//    labApp.Documents.CloseAll(true);//    labApp.Quit();//退出//    labApp = null;//    doc = null;//    GC.Collect(0);//}}}private void frmJP_CODESOFT_PT_Load(object sender, EventArgs e){if (dataGridView1.SelectedRows.Count > 0)lbStatus.Text = "總共" + dataGridView1.SelectedRows.Count.ToString() + "行需要列印";elselbStatus.Text = "總共1行需要列印";}private void btnClose_Click(object sender, EventArgs e){Close();}}
}

c#调用codesoft实现打印相关推荐

  1. c# 小票打印机打条形码_C#调用CODESOFT打印条码标签的关键代码

    C#调用CODESOFT打印条码标签的关键代码 在C#调用CODESOFT的实际过程中,会涉及到一些特别的业务需求,我们将C#调用CODESOFT的一些功能需求总结了一下,希望对大家有所帮助. 我们会 ...

  2. Delphi 调用Codesoft打印条码

    使用Delphi调用CodeSoft打印条码,使用OLE控件的方法.但需要注意的Codesoft是正式的安装版,使用绿色版不行,绿色版没有写注册表. 下面是测试通过的列子:(需要引用ComObj.Pa ...

  3. 调用浏览器的打印方法打印页面内容

    2018-08-30 直接调用浏览器的打印方法 1.打印按钮 <a href="#" target="_self" οnclick="print ...

  4. C#调用TSC条码打印机打印二维码(转)

    #region 调用TSC打印机打印/// <summary>/// 调用TSC打印机打印/// </summary>/// <param name="titl ...

  5. 调用PDF的打印命令

    调用PDF的打印命令,但是这种情况下是调用得服务器端的打印机环境,也就特定环境下能用. FileOutputStream fosw = new FileOutputStream(new File(&q ...

  6. C#实现调用打印机(打印字符串、打印绘图、打印图片),还差打印水晶报表

    C#实现调用打印机(打印字符串.打印绘图.打印图片),还差打印水晶报表 目的:调用打印机的使用 缺陷:打印的对象不全(还差打印水晶报表),不能实现在插件绘图板中画什么打印什么 改进:同缺陷,希望朋友们 ...

  7. c++调用win32API控制打印机打印

    win32实现将原始数据发送给打印机 1.调用OpenPrinter()打开打印机,获取打印机句柄. 2.初始化DOCINFO打印机结构体. 3.调用StartDocPrinter()表明应用程序准备 ...

  8. 调用浏览器局部打印,空白、只有一页问题、火狐兼容

    调用浏览器局部打印,空白.只有一页问题.火狐兼容 项目中需要局部打印页面的图表,图表类型多而杂,因此html结构中包含了canvas和iframe,iframe中又包含canvas. 刚开始根据网上的 ...

  9. C#调用TSC条码打印机打印二维码

    #region 调用TSC打印机打印/// <summary>/// 调用TSC打印机打印/// </summary>/// <param name="titl ...

最新文章

  1. python ffmpeg模块,python执行ffmpeg
  2. 可测试性如何帮助团队提升效率
  3. 查看数据库大小_查看Oracle 数据库的每天归档量及数据库大小
  4. Leetcode 220. 存在重复元素 III 解题思路及C++实现
  5. 不扯淡学数据库实践联系理论-课程
  6. Android O 前期预研之二:HIDL相关介绍
  7. 如何使用Soft-NMS实现目标检测并提升准确率
  8. python批量json文件转xml文件脚本(附代码)
  9. Qt::WA_OpaquePaintEvent理解
  10. hdu 5785 Interesting(manacher+前缀和)
  11. 命中注定码农路[一. 重新开始]
  12. c语言冒泡例子,C语言排序实例(选择、冒泡、插入、折半、快速)
  13. 浅析SkipList跳跃表原理及代码实现
  14. 「倍轻松」要上科创板,按摩器为什么总要和科技沾点边?
  15. Simulink中scope变为白色背景
  16. Android当方法总数超过64K时(Android Studio)
  17. illumina测序两束激发光分别是什么颜色,A/T/C/G四个碱基又分别标记了什么颜色的荧光素呢?
  18. 去健身房健身戴什么耳机好、最适合运动健身的健身房耳机推荐
  19. Hive数据仓库实战
  20. 王半仙儿的日记-0010——“在人生的十字路口,没有人会迷茫,但有人会胆怯。勤奋成就万事。”

热门文章

  1. 3GPP TR 38.885 Study on NR Vehicle-to-Everything (V2X) (Release 16)
  2. 用python做时间序列预测十:时间序列实践-航司乘客数预测
  3. 蚪侠镜像站群-V25版[泛域名+泛目录+泛内页]-1对1镜像-泛镜像-[代码+汉字]干扰-字体繁简切换-蜘蛛欺骗-主动推送-全局锚文本锁定-秒仿[PC+移动]端站点
  4. FCIP与FCoE之间的区别
  5. java:阿里云号码隐私服务使用
  6. 天翼云盘php插件,天翼云盘直接下载
  7. 面对Spring Boot 3最低支持Java17如洪水猛兽袭来,何去何从
  8. 数据结构——【队列】知识介绍+基本操作代码
  9. 手机地图渲染的方式讨论
  10. 2020年 Vue 面试题及答案 热门