รบกวนถามเรื่องคำสั่งบาร์โค้ด 39 หน่อยครับ

แนะนำ สอบถาม ภาษา C สำหรับผู้เริ่มต้น ภาษา Java ภาษา Python

Moderators: mindphp, ผู้ดูแลกระดาน

ณัฐวุฒิ

รบกวนถามเรื่องคำสั่งบาร์โค้ด 39 หน่อยครับ

Post by ณัฐวุฒิ »

รบกวนด้วยนะครับมือใหม่พอดีผมได้โค้ดต่อจากพี่อีกคนในบริษัทนะครับ โค้ดนี้เป็นบาร์โค้ด 128 ครับถ้าปริ้นยาวในกระดาษ A4 มันก็ปริ้นได้ปกติครับแต่พอนำมาปริ้นลง CARD เพื่อจะทำ PAYMENTCARD มันจะไม่อ่านครับอาจเพราะย่อมากเกินไปจึงอยากจะสอบถามว่าถ้าผมจะทำให้บาร์ดโค้ดนี้เป็น บาร์โค้ด 39 ต้องแก้ตรงไหนบ้างครับไม่แน่ใจว่า Code128Rendering.MakeBarcodeImage มีคำสั่งของโค้ด 39 ไหมครับขอบคุณครับ
มือใหม่จริงๆครับ

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

using GenCode128;

namespace Sample
{
/// <summary>
/// Summary description for Form1.
/// </summary>
public class frmMain : System.Windows.Forms.Form
{
private TextBox txtTitle;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.TextBox txtInput;
private System.Windows.Forms.PictureBox pictBarcode;
private System.Drawing.Printing.PrintDocument printDocument1;
private Label label3;
private TextBox textBox1;
private Label label4;
private TextBox textBox2;
private Label label5;
private TextBox textBox3;
private Label label6;
private TextBox textBox4;
// private TextBox textBox5;
// private TextBox textBox6;
// private TextBox textBox7;
// private TextBox textBox8;
private PictureBox pictureBox1;
private PictureBox pictureBox2;
private PictureBox pictureBox3;
private Label label2;
private Label label7;
private System.Windows.Forms.Button cmdPrint;
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;

public frmMain()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();

//
// TODO: Add any constructor code after InitializeComponent call
//
}

/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}

#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(frmMain));
this.label1 = new System.Windows.Forms.Label();
this.txtInput = new System.Windows.Forms.TextBox();
this.pictBarcode = new System.Windows.Forms.PictureBox();
this.printDocument1 = new System.Drawing.Printing.PrintDocument();
this.cmdPrint = new System.Windows.Forms.Button();
this.label3 = new System.Windows.Forms.Label();
this.textBox1 = new System.Windows.Forms.TextBox();
this.label4 = new System.Windows.Forms.Label();
this.textBox2 = new System.Windows.Forms.TextBox();
this.label5 = new System.Windows.Forms.Label();
this.textBox3 = new System.Windows.Forms.TextBox();
this.label6 = new System.Windows.Forms.Label();
this.textBox4 = new System.Windows.Forms.TextBox();
this.pictureBox1 = new System.Windows.Forms.PictureBox();
this.pictureBox2 = new System.Windows.Forms.PictureBox();
this.pictureBox3 = new System.Windows.Forms.PictureBox();
this.label2 = new System.Windows.Forms.Label();
this.label7 = new System.Windows.Forms.Label();
this.txtTitle = new System.Windows.Forms.TextBox();
((System.ComponentModel.ISupportInitialize)(this.pictBarcode)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.pictureBox2)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.pictureBox3)).BeginInit();
this.SuspendLayout();
//
// label1
//
this.label1.AutoSize = true;
this.label1.Font = new System.Drawing.Font("DilleniaUPC", 15.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(222)));
this.label1.Location = new System.Drawing.Point(15, 55);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(63, 28);
this.label1.TabIndex = 0;
this.label1.Text = "ชื่อลูกค้า :";
//
// txtInput
//
this.txtInput.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.txtInput.Font = new System.Drawing.Font("DilleniaUPC", 15.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(222)));
this.txtInput.Location = new System.Drawing.Point(149, 52);
this.txtInput.Name = "txtInput";
this.txtInput.Size = new System.Drawing.Size(241, 35);
this.txtInput.TabIndex = 1;
//
// pictBarcode
//
this.pictBarcode.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.pictBarcode.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.pictBarcode.Location = new System.Drawing.Point(495, 12);
this.pictBarcode.Name = "pictBarcode";
this.pictBarcode.Size = new System.Drawing.Size(12, 12);
this.pictBarcode.TabIndex = 3;
this.pictBarcode.TabStop = false;
this.pictBarcode.Visible = false;
//
// printDocument1
//
this.printDocument1.PrintPage += new System.Drawing.Printing.PrintPageEventHandler(this.printDocument1_PrintPage);
//
// cmdPrint
//
this.cmdPrint.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.cmdPrint.Location = new System.Drawing.Point(375, 236);
this.cmdPrint.Name = "cmdPrint";
this.cmdPrint.Size = new System.Drawing.Size(150, 46);
this.cmdPrint.TabIndex = 6;
this.cmdPrint.Text = "Print";
this.cmdPrint.Click += new System.EventHandler(this.cmdPrint_Click);
//
// label3
//
this.label3.AutoSize = true;
this.label3.Font = new System.Drawing.Font("DilleniaUPC", 15.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(222)));
this.label3.Location = new System.Drawing.Point(15, 95);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(102, 28);
this.label3.TabIndex = 0;
this.label3.Text = "TAX ของบริษัท :";
//
// textBox1
//
this.textBox1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.textBox1.Font = new System.Drawing.Font("DilleniaUPC", 15.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(222)));
this.textBox1.Location = new System.Drawing.Point(149, 92);
this.textBox1.Name = "textBox1";
this.textBox1.ReadOnly = true;
this.textBox1.Size = new System.Drawing.Size(116, 35);
this.textBox1.TabIndex = 1;
this.textBox1.Text = "XX";
//
// label4
//
this.label4.AutoSize = true;
this.label4.Font = new System.Drawing.Font("DilleniaUPC", 15.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(222)));
this.label4.Location = new System.Drawing.Point(15, 135);
this.label4.Name = "label4";
this.label4.Size = new System.Drawing.Size(113, 28);
this.label4.TabIndex = 0;
this.label4.Text = "รหัสลูกค้า(REF.1) :";
//
// textBox2
//
this.textBox2.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.textBox2.Font = new System.Drawing.Font("DilleniaUPC", 15.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(222)));
this.textBox2.Location = new System.Drawing.Point(149, 132);
this.textBox2.MaxLength = 5;
this.textBox2.Name = "textBox2";
this.textBox2.Size = new System.Drawing.Size(80, 35);
this.textBox2.TabIndex = 1;
//
// label5
//
this.label5.AutoSize = true;
this.label5.Font = new System.Drawing.Font("DilleniaUPC", 15.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(222)));
this.label5.Location = new System.Drawing.Point(15, 175);
this.label5.Name = "label5";
this.label5.Size = new System.Drawing.Size(124, 28);
this.label5.TabIndex = 0;
this.label5.Text = "เลขที่สัญญา(REF.2) :";
//
// textBox3
//
this.textBox3.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.textBox3.Font = new System.Drawing.Font("DilleniaUPC", 15.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(222)));
this.textBox3.Location = new System.Drawing.Point(149, 172);
this.textBox3.MaxLength = 10;
this.textBox3.Name = "textBox3";
this.textBox3.Size = new System.Drawing.Size(116, 35);
this.textBox3.TabIndex = 1;
//
// label6
//
this.label6.AutoSize = true;
this.label6.Font = new System.Drawing.Font("DilleniaUPC", 15.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(222)));
this.label6.Location = new System.Drawing.Point(15, 215);
this.label6.Name = "label6";
this.label6.Size = new System.Drawing.Size(87, 28);
this.label6.TabIndex = 0;
this.label6.Text = "ยอดชำระเงิน :";
//
// textBox4
//
this.textBox4.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.textBox4.Font = new System.Drawing.Font("DilleniaUPC", 15.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(222)));
this.textBox4.Location = new System.Drawing.Point(149, 212);
this.textBox4.Name = "textBox4";
this.textBox4.Size = new System.Drawing.Size(116, 35);
this.textBox4.TabIndex = 1;
//
// pictureBox1
//
this.pictureBox1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.pictureBox1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.pictureBox1.Location = new System.Drawing.Point(459, 12);
this.pictureBox1.Name = "pictureBox1";
this.pictureBox1.Size = new System.Drawing.Size(12, 12);
this.pictureBox1.TabIndex = 3;
this.pictureBox1.TabStop = false;
this.pictureBox1.Visible = false;
//
// pictureBox2
//
this.pictureBox2.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.pictureBox2.BackColor = System.Drawing.Color.Black;
this.pictureBox2.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.pictureBox2.Image = ((System.Drawing.Image)(resources.GetObject("pictureBox2.Image")));
this.pictureBox2.Location = new System.Drawing.Point(477, 12);
this.pictureBox2.Name = "pictureBox2";
this.pictureBox2.Size = new System.Drawing.Size(12, 12);
this.pictureBox2.TabIndex = 7;
this.pictureBox2.TabStop = false;
this.pictureBox2.Visible = false;
//
// pictureBox3
//
this.pictureBox3.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.pictureBox3.BackColor = System.Drawing.Color.Transparent;
this.pictureBox3.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.pictureBox3.Image = ((System.Drawing.Image)(resources.GetObject("pictureBox3.Image")));
this.pictureBox3.Location = new System.Drawing.Point(513, 12);
this.pictureBox3.Name = "pictureBox3";
this.pictureBox3.Size = new System.Drawing.Size(12, 12);
this.pictureBox3.TabIndex = 7;
this.pictureBox3.TabStop = false;
this.pictureBox3.Visible = false;
//
// label2
//
this.label2.AutoSize = true;
this.label2.Font = new System.Drawing.Font("DilleniaUPC", 15.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(222)));
this.label2.Location = new System.Drawing.Point(271, 215);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(77, 28);
this.label2.TabIndex = 0;
this.label2.Text = "บาทต่อเดือน";
//
// label7
//
this.label7.AutoSize = true;
this.label7.Font = new System.Drawing.Font("DilleniaUPC", 15.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(222)));
this.label7.Location = new System.Drawing.Point(15, 15);
this.label7.Name = "label7";
this.label7.Size = new System.Drawing.Size(109, 28);
this.label7.TabIndex = 0;
this.label7.Text = "ชื่อโครงการ/ยูนิต :";
//
// txtTitle
//
this.txtTitle.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.txtTitle.Font = new System.Drawing.Font("DilleniaUPC", 15.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(222)));
this.txtTitle.Location = new System.Drawing.Point(149, 12);
this.txtTitle.Name = "txtTitle";
this.txtTitle.Size = new System.Drawing.Size(241, 35);
this.txtTitle.TabIndex = 1;
//
// frmMain
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(537, 294);
this.Controls.Add(this.txtTitle);
this.Controls.Add(this.txtInput);
this.Controls.Add(this.textBox1);
this.Controls.Add(this.textBox2);
this.Controls.Add(this.textBox3);
this.Controls.Add(this.textBox4);
this.Controls.Add(this.cmdPrint);
this.Controls.Add(this.label2);
this.Controls.Add(this.label6);
this.Controls.Add(this.label5);
this.Controls.Add(this.label4);
this.Controls.Add(this.pictBarcode);
this.Controls.Add(this.label3);
this.Controls.Add(this.label7);
this.Controls.Add(this.label1);
this.Controls.Add(this.pictureBox3);
this.Controls.Add(this.pictureBox2);
this.Controls.Add(this.pictureBox1);
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
this.MaximizeBox = false;
this.MinimizeBox = false;
this.Name = "frmMain";
this.Text = "THACHANA PAYMENT CARD";
this.Load += new System.EventHandler(this.frmMain_Load);
((System.ComponentModel.ISupportInitialize)(this.pictBarcode)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.pictureBox2)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.pictureBox3)).EndInit();
this.ResumeLayout(false);
this.PerformLayout();

}
#endregion

/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new frmMain());
}

private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
/////////////////////////////////////////////////////////////////////////////////////////////////
//Process Print
/////////////////////////////////////////////////////////////////////////////////////////////////
using (Graphics g = e.Graphics)
{
using (Font fnt = new Font("DilleniaUPC", 12, FontStyle.Bold))
{
///ปรับระยะอักษรที่นี่
int adjX = 5;
int adjY = 5;
//Background
// g.DrawImage(pictureBox1.Image, 0, 0);

///Title
Font fntTitle = new Font("IrisUPC", 12, FontStyle.Bold | FontStyle.Underline);
string caption = string.Format("{0}",txtTitle.Text);
g.DrawString(caption, fntTitle, System.Drawing.Brushes.Black, adjX, adjY);
///Line
///g.DrawImage(pictureBox2.Image, adjX + 5, adjY = adjY + 20, 150, 1);

caption = string.Format("ชื่อ : {0}", txtInput.Text);
g.DrawString(caption, fnt, System.Drawing.Brushes.Black, adjX, adjY = adjY +15);

caption = string.Format("รหัสลูกค้า(REF.1) : {0}", textBox2.Text) + string.Format(" เลขที่สัญญา(REF.2) : {0}", textBox3.Text);
//caption = string.Format("Unit No. : {0}", textBox3.Text);
g.DrawString(caption, fnt, System.Drawing.Brushes.Black, adjX, adjY = adjY +15);

//caption = string.Format("Unit No. : {0}", textBox3.Text);
//g.DrawString(caption, fnt, System.Drawing.Brushes.Black, adjX, adjY = adjY +15);

caption = string.Format("ServiceCode:THACHANA ยอดชำระเงิน : {0:#,##0} บาทต่อเดือน", int.Parse(textBox4.Text));
g.DrawString(caption, fnt, System.Drawing.Brushes.Black, adjX, adjY = adjY +15);

caption = string.Format("ธนาคารกรุงศรีอยุธยา )");
g.DrawString(caption, fnt, System.Drawing.Brushes.Black, adjX, adjY = adjY + 20);

caption = string.Format("ธนาคารกสิกรไทย ");
g.DrawString(caption, fnt, System.Drawing.Brushes.Black, adjX, adjY = adjY + 15);

caption = string.Format("ธนาคารกรุงเทพ ");
g.DrawString(caption, fnt, System.Drawing.Brushes.Black, adjX, adjY = adjY + 15);

caption = string.Format("ธนาคารกรุงไทย ");
g.DrawString(caption, fnt, System.Drawing.Brushes.Black, adjX, adjY = adjY + 15);

caption = string.Format("www");
g.DrawString(caption, fnt, System.Drawing.Brushes.Black, adjX + 68, adjY = adjY + 20);


///White Line
g.DrawImage(pictureBox3.Image, 0, 155, 350, 60);
///Barcode
g.DrawImage(pictBarcode.Image, 0, 160, 340, 30);
///Show Barcode Number
caption = "|" + textBox1.Text + "00" + " " + textBox2.Text + " " + textBox3.Text + " " + textBox4.Text + "00";
g.DrawString(caption, fnt, System.Drawing.Brushes.Black, 50, 190);


}
}
}

private void cmdPrint_Click(object sender, System.EventArgs e)
{

///////////////////////////////////////////////////////////////////////////////////////////////
//Process Gen Barcode
///////////////////////////////////////////////////////////////////////////////////////////////
try
{
///Check total amount 1,000,000 UP
int intAmount = int.Parse(textBox4.Text);
string strAmount;
if (intAmount >= 1000000) { strAmount = "0"; }
else strAmount = intAmount.ToString() + "00";

Image myimg = Code128Rendering.MakeBarcodeImage("|" + textBox1.Text + "00" +"\n" + textBox2.Text + "\n" + textBox3.Text + "\n" + strAmount, 1, true);
pictBarcode.Image = myimg;
}
catch (Exception ex)
{
MessageBox.Show(this, ex.Message, this.Text);
}

///////////////////////////////////////////////////////////////////////////////////////////////
//Process Print
///////////////////////////////////////////////////////////////////////////////////////////////
printDocument1.Print();
}

private void frmMain_Load(object sender, EventArgs e)
{
// Construct an image object from a file in the local directory.
// ... This file must exist in the solution.
Image image = Image.FromFile("background.PNG");
// Set the PictureBox image property to this image.
// ... Then, adjust its height and width properties.
pictureBox1.Image = image;
}
}
}
  • Similar Topics
    Replies
    Views
    Last post

Return to “Programming - C/C++ & java & Python”

Who is online

Users browsing this forum: No registered users and 3 guests