C#打印条型码生成源程序.docx
《C#打印条型码生成源程序.docx》由会员分享,可在线阅读,更多相关《C#打印条型码生成源程序.docx(16页珍藏版)》请在冰豆网上搜索。
C#打印条型码生成源程序
C#打印条型码生成源程序
第一次在这里写东西,是想在这里认识更多的朋友,能与高手们交流,呵呵。
。
这个程序是早此时候要用到条形码时到处找资料,受别人启发,自己尝试开发的简单测试程序,希望对有需要的朋友有所帮助,其实本人也算是C#的初学者,最近刚用它为公司开发了一个数据库应用程序.呵呵..题外话就不多说了.下面就将代码贴出来,自己看去吧.谢谢大家,谢多多支持
usingSystem;
usingSystem.Drawing;
usingSystem.Collections;
usingSystem.ComponentModel;
usingSystem.Windows.Forms;
usingSystem.Data;
usingSystem.Runtime.InteropServices;
namespacebarcode
{
///
///Form1的摘要说明。
///
publicclassForm1:
System.Windows.Forms.Form
{
BitmapmemoryImage;
[DllImport("gdi32.dll")]
publicstaticexternlongBitBlt(IntPtrhdcDest,intNXDestt,intnYDest,intnWidth,intnHeight,IntPtrhdcSrc,intnXSrc,intnYSrc,System.Int32dwRop);
privateSystem.Windows.Forms.LinkLabellinkLabel1;
privateSystem.Windows.Forms.GroupBoxsetbarcode;
privateSystem.Windows.Forms.TextBoxbarcodewide;
privateSystem.Windows.Forms.TextBoxbarcodeleng;
privateSystem.Windows.Forms.Labellabel8;
privateSystem.Windows.Forms.Labellabel7;
privateSystem.Windows.Forms.ComboBoxto;
privateSystem.Windows.Forms.ComboBoxline;
privateSystem.Windows.Forms.Labellabel5;
privateSystem.Windows.Forms.Labellabel4;
privateSystem.Windows.Forms.ComboBoxstand2;
privateSystem.Windows.Forms.Labellabel3;
privateSystem.Windows.Forms.ComboBoxstand;
privateSystem.Windows.Forms.Labellabel1;
privateSystem.Windows.Forms.GroupBoxgroupBox2;
privateSystem.Windows.Forms.SaveFileDialogsaveFileDialog1;
privateSystem.Drawing.Printing.PrintDocumentprintDocument1;
privateSystem.Windows.Forms.Labellabel2;
privateSystem.Windows.Forms.TextBoxtextBox1;
privateSystem.Windows.Forms.Buttonsavebarcode;
privateSystem.Windows.Forms.Buttonprintbarcode;
privateAxBARCODELib.AxBarCodeCtrlBarCode1;
///
///必需的设计器变量。
///
privateSystem.ComponentModel.Containercomponents=null;
publicForm1()
{
//
//Windows窗体设计器支持所必需的
//
InitializeComponent();
//
//TODO:
在InitializeComponent调用后添加任何构造函数代码
//
}
///
///清理所有正在使用的资源。
///
protectedoverridevoidDispose(booldisposing)
{
if(disposing)
{
if(components!
=null)
{
components.Dispose();
}
}
base.Dispose(disposing);
}
#regionWindows窗体设计器生成的代码
///
///设计器支持所需的方法-不要使用代码编辑器修改
///此方法的内容。
///
privatevoidInitializeComponent()
{
System.Resources.ResourceManagerresources=newSystem.Resources.ResourceManager(typeof(Form1));
this.linkLabel1=newSystem.Windows.Forms.LinkLabel();
this.setbarcode=newSystem.Windows.Forms.GroupBox();
this.barcodewide=newSystem.Windows.Forms.TextBox();
this.barcodeleng=newSystem.Windows.Forms.TextBox();
this.label8=newSystem.Windows.Forms.Label();
this.label7=newSystem.Windows.Forms.Label();
this.to=newSystem.Windows.Forms.ComboBox();
this.line=newSystem.Windows.Forms.ComboBox();
this.label5=newSystem.Windows.Forms.Label();
this.label4=newSystem.Windows.Forms.Label();
this.stand2=newSystem.Windows.Forms.ComboBox();
this.label3=newSystem.Windows.Forms.Label();
this.stand=newSystem.Windows.Forms.ComboBox();
this.label1=newSystem.Windows.Forms.Label();
this.groupBox2=newSystem.Windows.Forms.GroupBox();
this.saveFileDialog1=newSystem.Windows.Forms.SaveFileDialog();
this.printDocument1=newSystem.Drawing.Printing.PrintDocument();
this.label2=newSystem.Windows.Forms.Label();
this.textBox1=newSystem.Windows.Forms.TextBox();
this.savebarcode=newSystem.Windows.Forms.Button();
this.printbarcode=newSystem.Windows.Forms.Button();
this.BarCode1=newAxBARCODELib.AxBarCodeCtrl();
this.setbarcode.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.BarCode1)).BeginInit();
this.SuspendLayout();
//
//linkLabel1
//
this.linkLabel1.LinkArea=newSystem.Windows.Forms.LinkArea(8,16);
this.linkLabel1.Location=newSystem.Drawing.Point(24,280);
this.linkLabel1.Name="linkLabel1";
this.linkLabel1.Size=newSystem.Drawing.Size(252,27);
this.linkLabel1.TabIndex=26;
this.linkLabel1.TabStop=true;
this.linkLabel1.Text="程序设计:
陈凌Fireling@";
//
//setbarcode
//
this.setbarcode.Controls.Add(this.barcodewide);
this.setbarcode.Controls.Add(this.barcodeleng);
this.setbarcode.Controls.Add(this.label8);
this.setbarcode.Controls.Add(this.label7);
this.setbarcode.Controls.Add(this.to);
this.setbarcode.Controls.Add(this.line);
this.setbarcode.Controls.Add(this.label5);
this.setbarcode.Controls.Add(this.label4);
this.setbarcode.Controls.Add(this.stand2);
this.setbarcode.Controls.Add(this.label3);
this.setbarcode.Controls.Add(this.stand);
this.setbarcode.Controls.Add(this.label1);
this.setbarcode.Location=newSystem.Drawing.Point(249,8);
this.setbarcode.Name="setbarcode";
this.setbarcode.Size=newSystem.Drawing.Size(272,224);
this.setbarcode.TabIndex=25;
this.setbarcode.TabStop=false;
this.setbarcode.Text="设置条形码";
//
//barcodewide
//
this.barcodewide.Location=newSystem.Drawing.Point(168,176);
this.barcodewide.Name="barcodewide";
this.barcodewide.Size=newSystem.Drawing.Size(74,21);
this.barcodewide.TabIndex=18;
this.barcodewide.Text="";
this.barcodewide.TextChanged+=newSystem.EventHandler(this.barcodewide_TextChanged);
//
//barcodeleng
//
this.barcodeleng.Location=newSystem.Drawing.Point(80,176);
this.barcodeleng.Name="barcodeleng";
this.barcodeleng.Size=newSystem.Drawing.Size(56,21);
this.barcodeleng.TabIndex=17;
this.barcodeleng.Text="";
this.barcodeleng.TextChanged+=newSystem.EventHandler(this.barcodeleng_TextChanged);
//
//label8
//
this.label8.AutoSize=true;
this.label8.Location=newSystem.Drawing.Point(144,176);
this.label8.Name="label8";
this.label8.Size=newSystem.Drawing.Size(11,17);
this.label8.TabIndex=16;
this.label8.Text="X";
//
//label7
//
this.label7.AutoSize=true;
this.label7.Location=newSystem.Drawing.Point(24,176);
this.label7.Name="label7";
this.label7.Size=newSystem.Drawing.Size(35,17);
this.label7.TabIndex=15;
this.label7.Text="长度:
";
//
//to
//
this.to.Location=newSystem.Drawing.Point(112,136);
this.to.Name="to";
this.to.Size=newSystem.Drawing.Size(141,20);
this.to.TabIndex=14;
this.to.SelectedIndexChanged+=newSystem.EventHandler(this.to_SelectedIndexChanged);
//
//line
//
this.line.Location=newSystem.Drawing.Point(112,104);
this.line.Name="line";
this.line.Size=newSystem.Drawing.Size(141,20);
this.line.TabIndex=13;
this.line.SelectedIndexChanged+=newSystem.EventHandler(this.line_SelectedIndexChanged);
//
//label5
//
this.label5.AutoSize=true;
this.label5.Location=newSystem.Drawing.Point(24,136);
this.label5.Name="label5";
this.label5.Size=newSystem.Drawing.Size(35,17);
this.label5.TabIndex=12;
this.label5.Text="方向:
";
//
//label4
//
this.label4.AutoSize=true;
this.label4.Location=newSystem.Drawing.Point(24,104);
this.label4.Name="label4";
this.label4.Size=newSystem.Drawing.Size(42,17);
this.label4.TabIndex=11;
this.label4.Text="线条:
";
//
//stand2
//
this.stand2.Location=newSystem.Drawing.Point(112,72);
this.stand2.Name="stand2";
this.stand2.Size=newSystem.Drawing.Size(141,20);
this.stand2.TabIndex=10;
this.stand2.SelectedIndexChanged+=newSystem.EventHandler(this.stand2_SelectedIndexChanged);
//
//label3
//
this.label3.AutoSize=true;
this.label3.Location=newSystem.Drawing.Point(24,72);
this.label3.Name="label3";
this.label3.Size=newSystem.Drawing.Size(42,17);
this.label3.TabIndex=9;
this.label3.Text="样式:
";
//
//stand
//
this.stand.Location=newSystem.Drawing.Point(112,37);
this.stand.Name="stand";
this.stand.Size=newSystem.Drawing.Size(140,20);
this.stand.TabIndex=1;
this.stand.SelectedIndexChanged+=newSystem.EventHandler(this.stand_SelectedIndexChanged);
//
//label1
//
this.label1.AutoSize=true;
this.label1.Location=newSystem.Drawing.Point(24,37);
this.label1.Name="label1";
this.label1.Size=newSystem.Drawing.Size(42,17);
this.label1.TabIndex=0;
this.label1.Text="标准:
";
//
//groupBox2
//
this.groupBox2.Location=newSystem.Drawing.Point(-23,256);
this.groupBox2.Name="groupBox2";
this.groupBox2.Size=newSystem.Drawing.Size(550,9);
this.groupBox2.TabIndex=24;
this.groupBox2.TabStop=false;
//
//saveFileDialog1
//
this.saveFileDialog1.DefaultExt="BMP";
this.saveFileDialog1.FileName="我的条形码";
this.saveFileDialog1.Filter="位图文件|*.BMP";
this.saveFileDialog1.Title="保存条形码";
//
//printDocument1
//
this.printDocument1.PrintPage+=newSystem.Drawing.Printing.PrintPageEventHandler(this.printDocument1_PrintPage);
//
//label2
//
this.label2.AutoSize=true;
this.label2.Location=newSystem.Drawing.Point(16,208);
this.label2.Name="label2";
this.label2.Size=newSystem.Drawing.Size(54,17);
this.label2.TabIndex=23;
this.label2.Text="条形码值";
//
//textBox1
//
this.textBox1.Location=newSystem.Drawing.Point(88,208);
this.textBox1.Name="textBox1";
this.textBox1.Size=newSystem.Drawing.Size(144,21);
this.textBox1.TabIndex=22;
this.textBox1.Text="";
this.textBox1.TextChanged+=newSystem.EventHandler(this.textBox1_TextChanged);
//
//savebarcode
//
this.savebarcode.Location=newSystem.Drawing.Point(321,280);
this.savebarcode.Name="savebarcode";
this.savebarcode.Size=newSystem.Drawing.Size(87,27);
this.savebarcode.TabIndex=20;
this.savebarcode.Text="保存条码";
this.savebarcode.Click+=newSystem.EventHandler(this.savebarcode_Click);
//
//printbarcode
//
this.printbar