C # print barrier code generation source

xiaoxiao2021-03-20  246

This app is to find information when you use the barcode in this time, inspired by others, trying to develop, you want to help the friends who need it, in fact, I am also a beginner of C #, recently used It develops a database application for the company. Ha ha. . I don't have much to say it. Let's post the code, look at it. Thank you, thank you for your support.

using System; using System.Drawing; using System.Collections; using System.ComponentModel; using System.Windows.Forms; using System.Data; using System.Runtime.InteropServices; namespace barcode {///

/// Form1 Abstract illustration. /// public class Form1: System.Windows.Forms.Form {Bitmap memoryImage; [DllImport ( "gdi32.dll")] public static extern long BitBlt (IntPtr hdcDest, int NXDestt, int nYDest, int nWidth, int nHeight, IntPtr hdcSrc, int nXSrc, int nYSrc, System.Int32 dwRop); private System.Windows.Forms.LinkLabel linkLabel1; private System.Windows.Forms.GroupBox setbarcode; private System.Windows.Forms.TextBox barcodewide; private System .Windows.Forms.TextBox barcodeleng; private System.Windows.Forms.Label label8; private System.Windows.Forms.Label label7; private System.Windows.Forms.ComboBox to; private System.Windows.Forms.ComboBox line; private System .Windows.Forms.Label label5; private System.Windows.Forms.Label label4; private System.Windows.Forms.ComboBox stand2; private System.Windows.Forms.Label label3; private System.Windows.Forms.ComboBox stand; private System .Windows.forms.label label1; private system.windows.forms.groupbox groupbox2; private system.windows.forms.sav eFileDialog saveFileDialog1; private System.Drawing.Printing.PrintDocument printDocument1; private System.Windows.Forms.Label label2; private System.Windows.Forms.TextBox textBox1; private System.Windows.Forms.Button savebarcode; private System.Windows.Forms. Button printbarcode; private axbarcodelib.axbarcodectrl barcode1; /// // / / must-have designer variable. /// private system.componentmodel.container components = null;

Public Form1 () {// // Windows Form Designer Support for // InitializationComponent (); // // Todo: Add any constructor code after INITIALIZECOMPONENT calls //}

///

/// Clean all the resources being used. /// Protected Override Void Dispose (Bool Disposing) {if (disponents! = Null) {components.dispose ();}} Base.Dispose

#REGION Windows Form Designer The code ///

/// designer supports the required method - do not use the code editor to modify the // / this method.

/// private void InitializeComponent () {System.Resources.ResourceManager resources = new System.Resources.ResourceManager (typeof (Form1)); this.linkLabel1 = new System.Windows.Forms.LinkLabel (); this. setbarcode = new System.Windows.Forms.GroupBox (); this.barcodewide = new System.Windows.Forms.TextBox (); this.barcodeleng = new System.Windows.Forms.TextBox (); this.label8 = new System. Windows.forms.label (); this.label7 = new system.windows.forms.label (); this.to = new system.windows.forms.combobox (); this.line = new system.Windows.Forms.comBOBOX (); This.Label5 = new system.windows.forms.label (); this.label4 = new system.windows.forms.label (); this.stand2 = new system.windows.forms.comBobox (); this. Label3 = new system.windows.forms.label (); this.stand = new system.windows.forms.comboBox (); this.label1 = new system.windows.forms.label (); this.groupbox2 = new system. Windows.Forms.groupBox (); this.savefiledialog1 = new system.windows.forms.savefi leDialog (); this.printDocument1 = new System.Drawing.Printing.PrintDocument (); this.label2 = new System.Windows.Forms.Label (); this.textBox1 = new System.Windows.Forms.TextBox (); this .savebarcode = new System.Windows.Forms.Button (); this.printbarcode = new System.Windows.Forms.Button (); this.BarCode1 = new AxBARCODELib.AxBarCodeCtrl (); this.setbarcode.SuspendLayout (); (( System.comPonentModel.isupportInitialize) (this.barcode1)))). Begininit (); this.suspendlayout (); // // linklabel1 // this.linklabel1.Linkarea = New System.Windows.Forms.Linkarea (8, 16); this.linklabel1.location =

New system.drawing.point (24, 280); this.linklabel1.name = "linklabel1"; this.linklabel1.size = new system.drawing.size (252, 27); this.linklabel1.tabindex = 26; this. Linklabel1.tabstop = true; this.linklabel1.text = program design: Chen Ling FireLing@126.com "; /// //etbarcode // 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. THIS.Stand2 .setbarcode.controls.add (this.label3); this.setbarcode.controls.add (this.stand); this.setbarcode.controls.add (this.label1); this.setbarcode.location = new system.drawing.point (249, 8); this.setbarcode.name = "setbarcode"; this.setbarcode.size = new system.drawing.size (272, 224); this.setbarc Ode.tabindex = 25; this.setbarcode.tabstop = false; this.setbarcode.text = "Set Barcode"; // // BarcodeWide // this.barcodeWide.Location = New System.drawing.Point (168, 176); this.barcodewide.Name = "barcodewide"; this.barcodewide.Size = new System.Drawing.Size (74, 21); this.barcodewide.TabIndex = 18; this.barcodewide.Text = ""; this.barcodewide.TextChanged = new System.EventHandler (this.barcodewide_TextChanged); // // barcodeleng // this.barcodeleng.Location = new System.Drawing.Point (80, 176); this.barcodeleng.Name = "barcodeleng"; this.barcodeleng .Size =

new System.Drawing.Size (56, 21); this.barcodeleng.TabIndex = 17; this.barcodeleng.Text = ""; this.barcodeleng.TextChanged = new System.EventHandler (this.barcodeleng_TextChanged); // // Label8 // this.label8.autosize = true; this.label8.location = new system.drawing.point (144, 176); this.label8.name = "label8"; this.label8.size = new system.drawing. Size (11, 17); this.label8.tabindex = 16; this.label8.text = "x"; /// Label7 // this.label7.Location = new system.drawing .Point (24, 176); this.label7.name = "label7"; this.label7.size = new system.drawing.size (35, 17); this.label7.TabINDEX = 15; this.label7.text = "Length:"; / // t // this.to.location = new system.drawing.point (112, 136); this.to.name = "to"; this.to.size = new system.drawing .Size (141, 20); this.to.tabindex = 14; this.to.Selected Indentexchanged = new system.eventhandler (this.to_selectedIndexchange); /// Line // this.line.lo CATION = new system.drawing.point (112, 104); this.Line.Name = "line"; this.line.size = new system.drawing.size (141, 20); this.Line.TabINDEX = 13; this.line.SelectedIndexChanged = new System.EventHandler (this.line_SelectedIndexChanged); // // label5 // this.label5.AutoSize = true; this.label5.Location = new System.Drawing.Point (24, 136); THISLABEL5.NAME = "label5"; this.label5.size = new system.drawing.size (35, 17); this.Label5.Tabindex = 12; this.label5.text = "direction:";

/// Label4 // this.label4.autosize = true; this.label4.Location = new system.drawing.point (24, 104); this.label4.name = "label4"; this.label4.size = new System.drawing.size (42, 17); this.label4.tabindex = 11; this.label4.text = "line:"; /// stand2 // this.stand2.Location = new system.drawing.point ( 112, 72); this.stand2.name = "stand2"; this.stand2.size = new system.drawing.size (141, 20); this.stand2.tabindex = 10; this.stand2.selectedIndexchanged = new system . EventHandler (this.stand2_selected); // // label3 // this.label3.autosize = true; this.label3.Location = new system.drawing.point (24, 72); this.label3.name = "label3" This.label3.size = new system.drawing.size (42, 17); this.label3.tabindex = 9; this.label3.text = "style:"; /// stand // this.stand.Location = New System.drawing.Point (112, 37); this.stand.Name = "stand"; this.stand.size = new system.drawing.size (140, 20); this.stand.tabindex = 1; this.stand.SelectedIndexChanged = new System.EventHandler (this.stand_SelectedIndexChanged); // // label1 // this.label1.AutoSize = true; this.label1.Location = new System.Drawing.Point (24, 37); THIS.Label1.name = "label1"; this.label1.size = new system.drawing.size (42, 17); this.label1.tabindex = 0; this.label1.text = "standard:"; // / / groupbox2 // this.groupBox2.Location = new system.drawing.point (-23, 256); this.groupbox2.name = "groupbox2"; this.groupbox2.size =

new System.Drawing.Size (550, 9); this.groupBox2.TabIndex = 24; this.groupBox2.TabStop = false; // // saveFileDialog1 // this.saveFileDialog1.DefaultExt = "BMP"; this.saveFileDialog1.FileName = "My Barcode"; this.savefiledialog1.filter = "Bitmap file | * .bmp"; this.savefiledialog1.title = "Save Barcode"; // // PrintDocument1 // this.printDocument1.printpage = new system1.printpage = new system .Drawing.Printing.PrintPageEventHandler (this.printDocument1_PrintPage); // // label2 // this.label2.AutoSize = true; this.label2.Location = new System.Drawing.Point (16, 208); this.label2.Name = "label2"; this.label2.Size = new System.Drawing.Size (54, 17); this.label2.TabIndex = 23; this.label2.Text = "bar code value"; // // textBox1 // this .TextBox1.Location = new system.drawing.point (88, 208); this.textbox1.name = "textBox1"; this.textbox1.size = new system.drawing.size (1444, 21); this.textbox1.tabindex = 22; this.TextBox1.text = ""; this.textbox1.textchanged = new system.eventhand ler (this.textBox1_TextChanged); // // savebarcode // this.savebarcode.Location = new System.Drawing.Point (321, 280); this.savebarcode.Name = "savebarcode"; this.savebarcode.Size = new System .Drawing.size (87, 27); this.savebarcode.tabindex = 20; this.savebarcode.text = "Save barcode"; this.savebarcode.click = new system.eventhandler (this.savebarcode_click); //// Printbarcode // this.printbarcode.location = new system.drawing.point (425, 280); this.printbarcode.name = "printbarcode"; this.printbarcode.size =

new System.Drawing.Size (87, 27); this.printbarcode.TabIndex = 21; this.printbarcode.Text = "print bar"; this.printbarcode.Click = new System.EventHandler (this.printbarcode_Click); // // barcode1 // this.barcode1.enabled = true; this.barcode1.location = new system.drawing.point (32, 24); this.barcode1.name = "barcode1"; this.barcode1.ocxState = ((System) .Windows.forms.axhost.state) ("Barcode1.ocxState"))))))))); this.barcode1.size = new system.drawing.size (200, 144); this.barcode1.tabindex = 27; / / // form1 // this.autoscalebasesize = new system.drawing.size (6, 14); this.clientsize = new system.drawing.size (544, 326); this.Controls.add (this.barcode1); this .Controls.add (this.groupbox2); this.controls.add (this.label2); this.controls.add (this.TextBox1); this.controls.add (this.savebarcode); this.controls.add (this .printbarcode; this.controls.add (this.linklabel1); this.controls.add (this.setbarcode); this.maximizebox = false; th Is.minimizeBox = false; this.name = "form1"; this.startPosition = system.windows.forms.formstartPosition.centerscreen; this.text = "Barcode generator"; this.Load = New System.EventHandler (this. Form1_load); this.setbarcode.ResumeLayout (false); (this.barcode1)). Endinit (); this.ResumeLayout (false);} #ENDREGION

///

/// The primary entry point of the application.

/// [statne "static void main () {Application.Run (new form1 ());} private void form1_load (Object sender, system.eventargs e) {barcode1.value =" 200409011649 "; // Standard this.stand.Items.Add ("UPC-A"); this.stand.Items.Add ("UPC-E"); this.stand.Items.Add ("EAN-13"); this.stand. Items.Add ("EAN-8"); this.stand.Items.Add ("Case Code"); this.stand.Items.Add ("Codabar (NW-T)"); this.stand.Items.Add ("CODE-39"); this.stand.Items.Add ("CODE-128"); this.stand.Items.Add ("US PostNet"); this.stand.Items.Add ("US Postal Fim" ); This.stand.items.Add ("JP POST"); // Style this.stand2.Items.Add ("standard"); this.stand2.Items.Add ("2-Digit Supplement"); this. Stand2.Items.Add ("5-Digit Supplement"); this.stand2.items.add ("POS Case Code"); // Line THISLINE.Items.Add ("Fine"); this.Line.Items .Add ("particularly light"); this.Line.Items.Add ("Fad"); this.Line.Items.Add ("Ordinary"); this.Line.Items.Add ("Medium"); Line.Items.Add ("Thick"); this.Line.Items.Add ("rich"); this.Line. Items.Add ("special"); // direction this.to.items.add ("0 degrees"); this.to.items.add ("90 degrees"); this.to.items.add (" 180 degrees "); this.to.items.Add (" 270 degrees "); this.barcodewide .text = barcode1.width.tostring (); this.barcodeleng.text = barcode1.Height .tostring ();} private void CaptureScreen () {Graphics mygraphics = BarCode1.CreateGraphics (); this.memoryImage = new Bitmap (BarCode1.Width, BarCode1.Height, mygraphics); Graphics memoryGraphics = Graphics.FromImage (memoryImage);

INTPTR DC1, DC2; DC1 = MyGraphics.GethDC (); DC2 = MemoryGraphics.GethDC (); Bitblt (DC2, 0, 0, Barcode1.Width, Barcode1.Height, DC1, 0, 0, 13369376); MyGraphics.ReleaseHDC ( dc1); memoryGraphics.ReleaseHdc (dc2);} private void savebarcode_Click (object sender, System.EventArgs e) {CaptureScreen (); DialogResult saveornot = saveFileDialog1.ShowDialog (); if (saveornot == DialogResult.OK) {memoryImage.Save (SaveFileDialog1.FileName, System.drawing.Imaging.ImageFormat.bmp);

MemoryImage.Save ("c: //temp//barcode1.bmp", system.drawing.image.imageformat.bmp);

Private Void PrintBarcode_Click (Object Sender, System.EventAndargs E) {this.captureScreen (); PrintDocument1.print ();

private void printDocument1_PrintPage (object sender, System.Drawing.Printing.PrintPageEventArgs e) {Point ulCorner = new Point (100, 100); e.Graphics.DrawImage (memoryImage, ulCorner);} private void stand_SelectedIndexChanged (object sender, System.EventArgs e) {INT i = stand.selectedIndIndex; Short II = short.parse (i.tostring ()); barode1.style = ii;}

Private Void Stand2_Selected IndexChanged (Object Sender, System.EventArgs E) {Int i = Stand2.SelectedIndIndex; Short II = short.parse (i.tostring ()); barode1.substyle = ii;

}

Private void line_selectedIndexchanged (Object sender, system.eventargs e) {Int i = stand.selectedIndIndex; Short II = short.parse (i.tostring ()); barcode1.LineWeight = II;}

Private void to_selected Indied IndexChanged (Object Sender, System.EventArgs E) {Int i = stand.selectedIndIndex; Short II = short.parse (i.tostring ()); barcode1.direction = ii;}

private void barcodeleng_TextChanged (object sender, System.EventArgs e) {if (this.barcodeleng.Text = ""!) {BarCode1.Width = int.Parse (this.barcodeleng.Text .Trim ());}} private void barcodewide_TextChanged (Object sender, system.eventargs e) {if (this.barcodeleng.text! = ") {barcode1.height = int.parse (this.barcodewide .text .trim ());}}

Private void textbox1_textchanged (object sender, system.eventargs e) {this.barcode1.value = this.TextBox1.text.trim ();

}} This program is passed under VS.NET 2003 WinXP.

转载请注明原文地址:https://www.9cbs.com/read-130406.html

New Post(0)