C#调用SoftCode打印条码,报错信息为将对象引用设置到对象实例,怎么解决

新手上路,请多包涵

应该是doc.Variables.FormVariables.Item("变量0").Value = "123";这一段没有“变量0”这个Item,但是在Codesoft中设置的是“变量0”。
直接上代码
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using LabelManager2;

namespace PrintTest
{

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

    private void btPrint_Click(object sender, EventArgs e)
    {
        if (!string.IsNullOrEmpty(txtBarcode.Text))
        {
            LabelManager2.ApplicationClass lbl = new LabelManager2.ApplicationClass();
            string labFileName = System.Windows.Forms.Application.StartupPath + @"\Document2.lab";
            try
            {
                if (!File.Exists(labFileName))
                {
                    MessageBox.Show("沒有找到標簽模板文件:LotPrint.Lab,請聯系系統管理員", "溫馨提示");
                    return;
                }
                lbl.Documents.Open(labFileName, false);// 调用设计好的label文件  
                LabelManager2.Document doc = lbl.ActiveDocument;
                doc.Variables.FormVariables.Item("变量0").Value = "123";
                //doc.PrintDocument(1);
            }
            catch (Exception ex)
            {
                MessageBox.Show("出錯啦,原因如下:\n\r" + ex.Message, "出錯啦");
            }
        }
    }
}

}

clipboard.png

阅读 3.6k
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进