OpenFileDialog ofd = new OpenFileDialog(); //选择要打印的Label档
ofd.ShowDialog();
textBox1.Text = ofd.FileName;
if (true)
{
labFile = ofd.FileName;
LabelManager2.Application labApp = new LabelManager2.Application();
labApp.Visible = true;
try
{
//labApp = new LabelManager2.Application();
//labApp.Visible = true;
labApp.Documents.Open(labFile, false);
filePath = "D:\\" + DateTime.Now.Year + DateTime.Now.Month + DateTime.Now.Day + DateTime.Now.Hour + DateTime.Now.Minute + DateTime.Now.Second + ".png";//保存图片的路径 为后面预览图片做准备
doc = labApp.ActiveDocument;
doc.Variables.FormVariables.Item("VAR00").Value = str.ToString();//向Label档传入变量
doc.Variables.FormVariables.Item("VAR01").Value = str.ToString();
string st = doc.CopyImageToFile(24, "PNG", 0, 100, filePath);
pictureBox1.Load(filePath); //以图片的形式浏览打印的Label
// doc.PrintDocument(1);
}
catch (Exception ex)
{
MessageBox.Show("出錯了,原因" + ex.Message);
}
finally
{
labApp.Documents.CloseAll(true);
labApp.Quit();
labApp = null;
doc = null;
}
}