基本信息
源码名称:C#扫描条码并打印 示例源码
源码大小:0.07M
文件格式:.zip
开发语言:C#
更新时间:2018-03-08
友情提示:(无需注册或充值,赞助后即可获取资源下载链接)
嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):78630559
本次赞助数额为: 2 元×
微信扫码支付:2 元
×
请留下您的邮箱,我们将在2小时内将文件发到您的邮箱
源码介绍
扫描条码后,打印机执行打印。
扫描条码后,打印机执行打印。
using System;
using System.Diagnostics;
using System.IO;
using System.Text;
using System.Windows.Forms;
namespace 条码打印_5_
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
/// <summary>
/// 打印的.TXT配置文件生成
/// </summary>
private void filecreat()
{
//获取条码的长宽;
int i = textBox4.Text.IndexOf(",") 1;
int j = textBox4.Text.Length;
string snl = textBox4.Text.Substring(0, i - 1);
string snw = textBox4.Text.Substring(i, j - i);
//获取字体的长宽
int x = textBox2.Text.IndexOf(",") 1;
int y = textBox2.Text.Length;
string codel = textBox2.Text.Substring(0, x - 1);
string codew = textBox2.Text.Substring(x, y - x);
//生成d:\Test.ini文档。
StreamWriter strmsave = new StreamWriter(@"d:\Test.ini", false, Encoding.Default);
if (checkBox1.Checked == true)
{
//获取描述的长宽
int h = textBox9.Text.IndexOf(",") 1;
int k = textBox9.Text.Length;
string depictl = textBox9.Text.Substring(0, h - 1);
string depictw = textBox9.Text.Substring(h, k - h);
strmsave.Write("^XA" Environment.NewLine
"^LH10,10" Environment.NewLine
"^FO" textBox1.Text "^A@N," codew "," codel ",R:MYSFC.TIF^FD" textBox6.Text textBox5.Text "^FS" Environment.NewLine
"^FO" textBox3.Text "^BY" snl "^BCN," snw ",N,N,N,N^FD" textBox5.Text "^FS" Environment.NewLine
"^FO" textBox8.Text "^A@N," codew "," codel ",R:MYSFC.TIF^FD" textBox7.Text "^FS" Environment.NewLine
"^PQ=1" Environment.NewLine "^XZ");
strmsave.Close();
}
else
{
strmsave.Write("^XA" Environment.NewLine
"^LH10,10" Environment.NewLine
"^FO" textBox3.Text "^BY" snl "^BCN," snw ",N,N,N,N^FD" textBox5.Text "^FS" Environment.NewLine
"^FO" textBox1.Text "^A@N," codew "," codel ",R:MYSFC.TIF^FD" textBox6.Text textBox5.Text "^FS" Environment.NewLine
"^PQ=1" Environment.NewLine "^XZ");
strmsave.Close();
}
}
private void button2_Click(object sender, EventArgs e)
{
if (File.Exists(@"d:\Test.ini"))
{
File.Delete(@"d:\Test.ini");
}
if (File.Exists(@"d:\Test.bat"))
{
File.Delete(@"d:\Test.ini");
}
//生成参数配置文件
StreamWriter strmsave1 = new StreamWriter(@"d:\Test.ini", false, Encoding.Default);
strmsave1.Write(@"^XA" Environment.NewLine "^LH10,10" Environment.NewLine "^FO25,25^BY3^BCN,30,N,N,N,N^FDCODE^FS" Environment.NewLine "^FO70,0^A@N,30,20,R:MYSFC.TIF^FDSN^FS" Environment.NewLine "^PQ=1" Environment.NewLine "^XZ");
strmsave1.Close();
//生成bat执行文件
StreamWriter strmsave2 = new StreamWriter(@"d:\Test.bat", false, System.Text.Encoding.Default);
strmsave2.Write(@"copy ""d:\Test.ini"" LPT1");
strmsave2.Close();
if (File.Exists(@"d:\Test.ini") && File.Exists(@"d:\Test.bat"))
{
MessageBox.Show("配置文件和执行文件生成OK");
}
}
private void button1_Click(object sender, EventArgs e)
{
if (textBox1.Text == "" || textBox2.Text == "" || textBox3.Text == "" || textBox4.Text == "")
{
MessageBox.Show("字符不能留空");
return;
}
filecreat();
if (File.Exists(@"d:\Test.bat"))
{
Process.Start(@"d:\test.bat");
}
else
{
StreamWriter strmsave = new StreamWriter(@"d:\Test.bat", false, System.Text.Encoding.Default);
strmsave.Write(@"copy ""d:\Test.ini"" LPT1");
strmsave.Close();
Process.Start(@"d:\test.bat");
}
textBox5.Focus();
textBox5.SelectAll();
}
private void Form1_Load(object sender, EventArgs e)
{
textBox1.Text = "70,40";
textBox2.Text = "30,20";
textBox3.Text = "20,0";
textBox4.Text = "3,30";
textBox8.Text = "15,50";
textBox9.Text = "30,20";
}
private void textBox5_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
{
button1.Focus();
button1_Click(sender, e); //调用按钮的事件处理代码
}
}
}
}