using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms;namespace BarCodeTest { public partial class Form4 : Form { public Form4() { InitializeComponent(); this.Paint += new PaintEventHandler(Form4_Paint); } void Form4_Paint(object sender, PaintEventArgs e) { Rectangle barcoderect = new Rectangle(10, 10, 250, 48); BarCode39 barcode = new BarCode39(); barcode.BarcodeText = "69555555555555";
barcode.DrawBarcode(e.Graphics, barcoderect); } } /********************************分割线***********************************/ public class BarCode39 { public string BarcodeText = string.Empty; public int BarcodeHeight = 0; public int BarcodeWidth = 0; public Font footerFont = new Font("微软雅黑", 12.0f); /*修改了字体大小*/ private double wideToNarrowRatio = 3.0; public double WideToNarrowRatio { get { return wideToNarrowRatio; } set { wideToNarrowRatio = value; } } private int weight = 1; public int Weight { get { return weight; } set { weight = value; } } /// <summary> /// 39条码中能使用的字符 /// </summary> private String alphabet39 = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-. $/+%*"; private String[] coded39Char = { /* 0 */ "001100100", /* 1 */ "100010100", /* 2 */ "010010100", /* 3 */ "110000100", /* 4 */ "001010100", /* 5 */ "101000100", /* 6 */ "011000100", /* 7 */ "000110100", /* 8 */ "100100100", /* 9 */ "010100100", /* A */ "100010010", /* B */ "010010010", /* C */ "110000010", /* D */ "001010010", /* E */ "101000010", /* F */ "011000010", /* G */ "000110010", /* H */ "100100010", /* I */ "010100010", /* J */ "001100010", /* K */ "100010001", /* L */ "010010001", /* M */ "110000001", /* N */ "001010001", /* O */ "101000001", /* P */ "011000001", /* Q */ "000110001", /* R */ "100100001", /* S */ "010100001", /* T */ "001100001", /* U */ "100011000", /* V */ "010011000", /* W */ "110001000", /* X */ "001011000", /* Y */ "101001000", /* Z */ "011001000", /* - */ "000111000", /* . */ "110000100", /*' '*/ "011000100", /* $ */ "010101000", /* / */ "010100010", /* + */ "010001010", /* % */ "100101000", /* * */ "001101000" }; public BarCode39() { BarcodeText = "1234"; } /// <summary> /// 为了使得条形码居中先要计算条形码的Left和Top坐标 /// </summary> /// <returns></returns> private int getX() { int currentLocation = 0; string strBarcode = "*" + BarcodeText.ToUpper() + "*"; for (int i = 0; i < strBarcode.Length; i++) { string encodedString = coded39Char[alphabet39.IndexOf(strBarcode[i])]; for (int j = 0; j < 5; j++) { if (encodedString[j] == '0') { currentLocation += weight; } else { currentLocation += 3 * weight; } //画第6个 5 白条 if ((j + 5) < 9) { if (encodedString[j + 5] == '0') { currentLocation += weight; } else { currentLocation += 3 * weight; } } } currentLocation += weight; } return currentLocation; } /// <summary> /// 显示条形码 /// </summary> /// <param name="g">GDI+</param> /// <param name="rects">画图区域</param> protected void DrawBitmap(Graphics g, Rectangle rects) { if (BarcodeText == "") return; string strBarcode = "*" + BarcodeText.ToUpper() + "*"; //string strBarcode = BarcodeText.ToUpper() ; String encodedString = ""; int currentLocation = rects.X + (rects.Width - getX()) / 2; SolidBrush blackBrush = new SolidBrush(Color.Black); SolidBrush witeBrush = new SolidBrush(Color.White); int yTop = rects.Y; for (int i = 0; i < strBarcode.Length; i++) { encodedString = coded39Char[alphabet39.IndexOf(strBarcode[i])]; for (int j = 0; j < 5; j++) { if (encodedString[j] == '0') { Rectangle re1 = new Rectangle(currentLocation, yTop, weight, BarcodeHeight); g.FillRectangle(blackBrush, re1); currentLocation += weight; } else { Rectangle re1 = new Rectangle(currentLocation, yTop, 3 * weight, BarcodeHeight); g.FillRectangle(blackBrush, re1); currentLocation += 3 * weight; } //画第6个 5 白条 if ((j + 5) < 9) { if (encodedString[j + 5] == '0') { Rectangle re1 = new Rectangle(currentLocation, yTop, weight, BarcodeHeight); g.FillRectangle(witeBrush, re1); currentLocation += weight; } else { Rectangle re1 = new Rectangle(currentLocation, yTop, 3 * weight, BarcodeHeight); g.FillRectangle(witeBrush, re1); currentLocation += 3 * weight; } } } Rectangle re2 = new Rectangle(currentLocation, yTop, weight, BarcodeHeight); g.FillRectangle(witeBrush, re2); currentLocation += weight; } } /// <summary> /// 显示条形码和文字 /// </summary> /// <param name="g"></param> /// <param name="rects"></param> public void DrawBarcode(Graphics g, Rectangle rects) { SizeF fsize = g.MeasureString(BarcodeText, this.footerFont); Rectangle b = rects; b.Y = rects.Y + rects.Height - (int)fsize.Height; b.X = rects.X + (rects.Width - (int)fsize.Width) / 2; b.Height = (int)fsize.Height; DrawText(BarcodeText, g, b); //BarCode Rectangle m = new Rectangle(); m = rects; m.Height = rects.Height - b.Height; this.BarcodeHeight = m.Height; DrawBitmap(g, m); } /// <summary> /// 绘制条形码 无文字 /// </summary> /// <param name="g"></param> /// <param name="rects"></param> public void DrawBarBit(Graphics g, Rectangle rects) { SizeF fsize = g.MeasureString(BarcodeText, this.footerFont); Rectangle b = rects; b.Y = rects.Y + rects.Height - (int)fsize.Height; b.X = rects.X + (rects.Width - (int)fsize.Width) / 2; b.Height = (int)fsize.Height; //DrawText(BarcodeText, g, b); //BarCode Rectangle m = new Rectangle(); m = rects; m.Height = rects.Height - b.Height; this.BarcodeHeight = m.Height; DrawBitmap(g, m); } /// <summary> /// 文本显示 /// </summary> /// <param name="text"></param> /// <param name="g"></param> /// <param name="rects"></param> protected void DrawText(string text, Graphics g, Rectangle rects) { g.DrawString(text, this.footerFont, Brushes.Black, rects); } } }
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms;namespace BarCodeTest { public partial class Form4 : Form { public Form4() { InitializeComponent(); this.Paint += new PaintEventHandler(Form4_Paint); } void Form4_Paint(object sender, PaintEventArgs e) { Rectangle barcoderect = new Rectangle(10, 10, 250, 48); BarCode39 barcode = new BarCode39(); barcode.BarcodeText = "69555555555555";
barcode.DrawBarcode(e.Graphics, barcoderect); } } public class BarCode39 { public string BarcodeText = string.Empty; public int BarcodeHeight = 0; public int BarcodeWidth = 0; public Font footerFont = new Font("微软雅黑", 13.0f); /*Bob 修改了字体大小*/ private double wideToNarrowRatio = 3.0; public double WideToNarrowRatio { get { return wideToNarrowRatio; } set { wideToNarrowRatio = value; } } private int weight = 1; public int Weight { get { return weight; } set { weight = value; } } /// <summary> /// 39条码中能使用的字符 /// </summary> private String alphabet39 = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-. $/+%*"; private String[] coded39Char = { /* 0 */ "001100100", /* 1 */ "100010100", /* 2 */ "010010100", /* 3 */ "110000100", /* 4 */ "001010100", /* 5 */ "101000100", /* 6 */ "011000100", /* 7 */ "000110100", /* 8 */ "100100100", /* 9 */ "010100100", /* A */ "100010010", /* B */ "010010010", /* C */ "110000010", /* D */ "001010010", /* E */ "101000010", /* F */ "011000010", /* G */ "000110010", /* H */ "100100010", /* I */ "010100010", /* J */ "001100010", /* K */ "100010001", /* L */ "010010001", /* M */ "110000001", /* N */ "001010001", /* O */ "101000001", /* P */ "011000001", /* Q */ "000110001", /* R */ "100100001", /* S */ "010100001", /* T */ "001100001", /* U */ "100011000", /* V */ "010011000", /* W */ "110001000", /* X */ "001011000", /* Y */ "101001000", /* Z */ "011001000", /* - */ "000111000", /* . */ "110000100", /*' '*/ "011000100", /* $ */ "010101000", /* / */ "010100010", /* + */ "010001010", /* % */ "100101000", /* * */ "001101000" }; public BarCode39() { BarcodeText = "1234"; } /// <summary> /// 为了使得条形码居中先要计算条形码的Left和Top坐标 /// </summary> /// <returns></returns> private int getX() { int currentLocation = 0; string strBarcode = "*" + BarcodeText.ToUpper() + "*"; for (int i = 0; i < strBarcode.Length; i++) { string encodedString = coded39Char[alphabet39.IndexOf(strBarcode[i])]; for (int j = 0; j < 5; j++) { if (encodedString[j] == '0') { currentLocation += weight; } else { currentLocation += 3 * weight; } //画第6个 5 白条 if ((j + 5) < 9) { if (encodedString[j + 5] == '0') { currentLocation += weight; } else { currentLocation += 3 * weight; } } } currentLocation += weight; } return currentLocation; } /// <summary> /// 显示条形码 /// </summary> /// <param name="g">GDI+</param> /// <param name="rects">画图区域</param> protected void DrawBitmap(Graphics g, Rectangle rects) { if (BarcodeText == "") return; string strBarcode = "*" + BarcodeText.ToUpper() + "*"; //string strBarcode = BarcodeText.ToUpper() ; String encodedString = ""; int currentLocation = rects.X + (rects.Width - getX()) / 2; SolidBrush blackBrush = new SolidBrush(Color.Black); SolidBrush witeBrush = new SolidBrush(Color.White); int yTop = rects.Y; for (int i = 0; i < strBarcode.Length; i++) { encodedString = coded39Char[alphabet39.IndexOf(strBarcode[i])]; for (int j = 0; j < 5; j++) { if (encodedString[j] == '0') { Rectangle re1 = new Rectangle(currentLocation, yTop, weight, BarcodeHeight); g.FillRectangle(blackBrush, re1); currentLocation += weight; } else { Rectangle re1 = new Rectangle(currentLocation, yTop, 3 * weight, BarcodeHeight); g.FillRectangle(blackBrush, re1); currentLocation += 3 * weight; } //画第6个 5 白条 if ((j + 5) < 9) { if (encodedString[j + 5] == '0') { Rectangle re1 = new Rectangle(currentLocation, yTop, weight, BarcodeHeight); g.FillRectangle(witeBrush, re1); currentLocation += weight; } else { Rectangle re1 = new Rectangle(currentLocation, yTop, 3 * weight, BarcodeHeight); g.FillRectangle(witeBrush, re1); currentLocation += 3 * weight; } } } Rectangle re2 = new Rectangle(currentLocation, yTop, weight, BarcodeHeight); g.FillRectangle(witeBrush, re2); currentLocation += weight; } } /// <summary> /// 显示条形码和文字 /// </summary> /// <param name="g"></param> /// <param name="rects"></param> public void DrawBarcode(Graphics g, Rectangle rects) { SizeF fsize = g.MeasureString(BarcodeText, this.footerFont); Rectangle b = rects; b.Y = rects.Y + rects.Height - (int)fsize.Height; b.X = rects.X + (rects.Width - (int)fsize.Width) / 2; b.Height = (int)fsize.Height; DrawText(BarcodeText, g, b); //BarCode Rectangle m = new Rectangle(); m = rects; m.Height = rects.Height - b.Height; this.BarcodeHeight = m.Height; DrawBitmap(g, m); } /// <summary> /// 绘制条形码 无文字 /// </summary> /// <param name="g"></param> /// <param name="rects"></param> public void DrawBarBit(Graphics g, Rectangle rects) { SizeF fsize = g.MeasureString(BarcodeText, this.footerFont); Rectangle b = rects; b.Y = rects.Y + rects.Height - (int)fsize.Height; b.X = rects.X + (rects.Width - (int)fsize.Width) / 2; b.Height = (int)fsize.Height; //DrawText(BarcodeText, g, b); //BarCode Rectangle m = new Rectangle(); m = rects; m.Height = rects.Height - b.Height; this.BarcodeHeight = m.Height; DrawBitmap(g, m); } /// <summary> /// 文本显示 /// </summary> /// <param name="text"></param> /// <param name="g"></param> /// <param name="rects"></param> protected void DrawText(string text, Graphics g, Rectangle rects) { g.DrawString(text, this.footerFont, Brushes.Black, rects); } } }
http://www.cnblogs.com/xmonkey2001/archive/2009/11/10/1600084.html
DataTable dt = new DataTable();
dt.Columns.Add("TextFiled", typeof(string));
dt.Rows.Add("a123456");
dt.Rows.Add("b123457");
dt.Rows.Add("c123458");
EnginManage manage = new EnginManage(); string message = manage.startengin();
string error = manage.QueueTasks(dt);
string temp = manage.stop();
上面是我的代码 使用的时候只打印第一个 后面两个都不打印
Process.Start(bartendAdd, "/NOSPLASH /F=\"" + btw + "\" /D=\"" + sn + "\" /P /X");
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;namespace BarCodeTest
{
public partial class Form4 : Form
{
public Form4()
{
InitializeComponent();
this.Paint += new PaintEventHandler(Form4_Paint);
} void Form4_Paint(object sender, PaintEventArgs e)
{
Rectangle barcoderect = new Rectangle(10, 10, 250, 48);
BarCode39 barcode = new BarCode39();
barcode.BarcodeText = "69555555555555";
barcode.DrawBarcode(e.Graphics, barcoderect);
}
}
/********************************分割线***********************************/
public class BarCode39
{
public string BarcodeText = string.Empty; public int BarcodeHeight = 0;
public int BarcodeWidth = 0; public Font footerFont = new Font("微软雅黑", 12.0f); /*修改了字体大小*/ private double wideToNarrowRatio = 3.0; public double WideToNarrowRatio
{
get { return wideToNarrowRatio; }
set { wideToNarrowRatio = value; }
}
private int weight = 1; public int Weight
{
get { return weight; }
set { weight = value; }
}
/// <summary>
/// 39条码中能使用的字符
/// </summary>
private String alphabet39 = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-. $/+%*"; private String[] coded39Char =
{
/* 0 */ "001100100",
/* 1 */ "100010100",
/* 2 */ "010010100",
/* 3 */ "110000100",
/* 4 */ "001010100",
/* 5 */ "101000100",
/* 6 */ "011000100",
/* 7 */ "000110100",
/* 8 */ "100100100",
/* 9 */ "010100100",
/* A */ "100010010",
/* B */ "010010010",
/* C */ "110000010",
/* D */ "001010010",
/* E */ "101000010",
/* F */ "011000010",
/* G */ "000110010",
/* H */ "100100010",
/* I */ "010100010",
/* J */ "001100010",
/* K */ "100010001",
/* L */ "010010001",
/* M */ "110000001",
/* N */ "001010001",
/* O */ "101000001",
/* P */ "011000001",
/* Q */ "000110001",
/* R */ "100100001",
/* S */ "010100001",
/* T */ "001100001",
/* U */ "100011000",
/* V */ "010011000",
/* W */ "110001000",
/* X */ "001011000",
/* Y */ "101001000",
/* Z */ "011001000",
/* - */ "000111000",
/* . */ "110000100",
/*' '*/ "011000100",
/* $ */ "010101000",
/* / */ "010100010",
/* + */ "010001010",
/* % */ "100101000",
/* * */ "001101000"
}; public BarCode39()
{
BarcodeText = "1234";
}
/// <summary>
/// 为了使得条形码居中先要计算条形码的Left和Top坐标
/// </summary>
/// <returns></returns>
private int getX()
{
int currentLocation = 0;
string strBarcode = "*" + BarcodeText.ToUpper() + "*";
for (int i = 0; i < strBarcode.Length; i++)
{
string encodedString = coded39Char[alphabet39.IndexOf(strBarcode[i])]; for (int j = 0; j < 5; j++)
{ if (encodedString[j] == '0')
{
currentLocation += weight;
}
else
{
currentLocation += 3 * weight;
}
//画第6个 5 白条
if ((j + 5) < 9)
{
if (encodedString[j + 5] == '0')
{
currentLocation += weight;
}
else
{
currentLocation += 3 * weight;
}
}
}
currentLocation += weight;
}
return currentLocation;
}
/// <summary>
/// 显示条形码
/// </summary>
/// <param name="g">GDI+</param>
/// <param name="rects">画图区域</param>
protected void DrawBitmap(Graphics g, Rectangle rects)
{
if (BarcodeText == "") return;
string strBarcode = "*" + BarcodeText.ToUpper() + "*";
//string strBarcode = BarcodeText.ToUpper() ;
String encodedString = "";
int currentLocation = rects.X + (rects.Width - getX()) / 2;
SolidBrush blackBrush = new SolidBrush(Color.Black);
SolidBrush witeBrush = new SolidBrush(Color.White);
int yTop = rects.Y;
for (int i = 0; i < strBarcode.Length; i++)
{
encodedString = coded39Char[alphabet39.IndexOf(strBarcode[i])]; for (int j = 0; j < 5; j++)
{ if (encodedString[j] == '0')
{
Rectangle re1 = new Rectangle(currentLocation, yTop, weight, BarcodeHeight);
g.FillRectangle(blackBrush, re1);
currentLocation += weight;
}
else
{
Rectangle re1 = new Rectangle(currentLocation, yTop, 3 * weight, BarcodeHeight);
g.FillRectangle(blackBrush, re1);
currentLocation += 3 * weight;
}
//画第6个 5 白条
if ((j + 5) < 9)
{
if (encodedString[j + 5] == '0')
{
Rectangle re1 = new Rectangle(currentLocation, yTop, weight, BarcodeHeight);
g.FillRectangle(witeBrush, re1);
currentLocation += weight;
}
else
{
Rectangle re1 = new Rectangle(currentLocation, yTop, 3 * weight, BarcodeHeight);
g.FillRectangle(witeBrush, re1);
currentLocation += 3 * weight;
}
}
}
Rectangle re2 = new Rectangle(currentLocation, yTop, weight, BarcodeHeight);
g.FillRectangle(witeBrush, re2);
currentLocation += weight;
}
} /// <summary>
/// 显示条形码和文字
/// </summary>
/// <param name="g"></param>
/// <param name="rects"></param>
public void DrawBarcode(Graphics g, Rectangle rects)
{
SizeF fsize = g.MeasureString(BarcodeText, this.footerFont); Rectangle b = rects;
b.Y = rects.Y + rects.Height - (int)fsize.Height;
b.X = rects.X + (rects.Width - (int)fsize.Width) / 2;
b.Height = (int)fsize.Height;
DrawText(BarcodeText, g, b);
//BarCode
Rectangle m = new Rectangle();
m = rects;
m.Height = rects.Height - b.Height;
this.BarcodeHeight = m.Height;
DrawBitmap(g, m);
} /// <summary>
/// 绘制条形码 无文字
/// </summary>
/// <param name="g"></param>
/// <param name="rects"></param>
public void DrawBarBit(Graphics g, Rectangle rects)
{
SizeF fsize = g.MeasureString(BarcodeText, this.footerFont); Rectangle b = rects;
b.Y = rects.Y + rects.Height - (int)fsize.Height;
b.X = rects.X + (rects.Width - (int)fsize.Width) / 2;
b.Height = (int)fsize.Height;
//DrawText(BarcodeText, g, b);
//BarCode
Rectangle m = new Rectangle();
m = rects;
m.Height = rects.Height - b.Height;
this.BarcodeHeight = m.Height;
DrawBitmap(g, m);
}
/// <summary>
/// 文本显示
/// </summary>
/// <param name="text"></param>
/// <param name="g"></param>
/// <param name="rects"></param>
protected void DrawText(string text, Graphics g, Rectangle rects)
{
g.DrawString(text, this.footerFont, Brushes.Black, rects);
} }
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;namespace BarCodeTest
{
public partial class Form4 : Form
{
public Form4()
{
InitializeComponent();
this.Paint += new PaintEventHandler(Form4_Paint);
} void Form4_Paint(object sender, PaintEventArgs e)
{
Rectangle barcoderect = new Rectangle(10, 10, 250, 48);
BarCode39 barcode = new BarCode39();
barcode.BarcodeText = "69555555555555";
barcode.DrawBarcode(e.Graphics, barcoderect);
}
} public class BarCode39
{
public string BarcodeText = string.Empty; public int BarcodeHeight = 0;
public int BarcodeWidth = 0; public Font footerFont = new Font("微软雅黑", 13.0f); /*Bob 修改了字体大小*/ private double wideToNarrowRatio = 3.0; public double WideToNarrowRatio
{
get { return wideToNarrowRatio; }
set { wideToNarrowRatio = value; }
}
private int weight = 1; public int Weight
{
get { return weight; }
set { weight = value; }
}
/// <summary>
/// 39条码中能使用的字符
/// </summary>
private String alphabet39 = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-. $/+%*"; private String[] coded39Char =
{
/* 0 */ "001100100",
/* 1 */ "100010100",
/* 2 */ "010010100",
/* 3 */ "110000100",
/* 4 */ "001010100",
/* 5 */ "101000100",
/* 6 */ "011000100",
/* 7 */ "000110100",
/* 8 */ "100100100",
/* 9 */ "010100100",
/* A */ "100010010",
/* B */ "010010010",
/* C */ "110000010",
/* D */ "001010010",
/* E */ "101000010",
/* F */ "011000010",
/* G */ "000110010",
/* H */ "100100010",
/* I */ "010100010",
/* J */ "001100010",
/* K */ "100010001",
/* L */ "010010001",
/* M */ "110000001",
/* N */ "001010001",
/* O */ "101000001",
/* P */ "011000001",
/* Q */ "000110001",
/* R */ "100100001",
/* S */ "010100001",
/* T */ "001100001",
/* U */ "100011000",
/* V */ "010011000",
/* W */ "110001000",
/* X */ "001011000",
/* Y */ "101001000",
/* Z */ "011001000",
/* - */ "000111000",
/* . */ "110000100",
/*' '*/ "011000100",
/* $ */ "010101000",
/* / */ "010100010",
/* + */ "010001010",
/* % */ "100101000",
/* * */ "001101000"
}; public BarCode39()
{
BarcodeText = "1234";
}
/// <summary>
/// 为了使得条形码居中先要计算条形码的Left和Top坐标
/// </summary>
/// <returns></returns>
private int getX()
{
int currentLocation = 0;
string strBarcode = "*" + BarcodeText.ToUpper() + "*";
for (int i = 0; i < strBarcode.Length; i++)
{
string encodedString = coded39Char[alphabet39.IndexOf(strBarcode[i])]; for (int j = 0; j < 5; j++)
{ if (encodedString[j] == '0')
{
currentLocation += weight;
}
else
{
currentLocation += 3 * weight;
}
//画第6个 5 白条
if ((j + 5) < 9)
{
if (encodedString[j + 5] == '0')
{
currentLocation += weight;
}
else
{
currentLocation += 3 * weight;
}
}
}
currentLocation += weight;
}
return currentLocation;
}
/// <summary>
/// 显示条形码
/// </summary>
/// <param name="g">GDI+</param>
/// <param name="rects">画图区域</param>
protected void DrawBitmap(Graphics g, Rectangle rects)
{
if (BarcodeText == "") return;
string strBarcode = "*" + BarcodeText.ToUpper() + "*";
//string strBarcode = BarcodeText.ToUpper() ;
String encodedString = "";
int currentLocation = rects.X + (rects.Width - getX()) / 2;
SolidBrush blackBrush = new SolidBrush(Color.Black);
SolidBrush witeBrush = new SolidBrush(Color.White);
int yTop = rects.Y;
for (int i = 0; i < strBarcode.Length; i++)
{
encodedString = coded39Char[alphabet39.IndexOf(strBarcode[i])]; for (int j = 0; j < 5; j++)
{ if (encodedString[j] == '0')
{
Rectangle re1 = new Rectangle(currentLocation, yTop, weight, BarcodeHeight);
g.FillRectangle(blackBrush, re1);
currentLocation += weight;
}
else
{
Rectangle re1 = new Rectangle(currentLocation, yTop, 3 * weight, BarcodeHeight);
g.FillRectangle(blackBrush, re1);
currentLocation += 3 * weight;
}
//画第6个 5 白条
if ((j + 5) < 9)
{
if (encodedString[j + 5] == '0')
{
Rectangle re1 = new Rectangle(currentLocation, yTop, weight, BarcodeHeight);
g.FillRectangle(witeBrush, re1);
currentLocation += weight;
}
else
{
Rectangle re1 = new Rectangle(currentLocation, yTop, 3 * weight, BarcodeHeight);
g.FillRectangle(witeBrush, re1);
currentLocation += 3 * weight;
}
}
}
Rectangle re2 = new Rectangle(currentLocation, yTop, weight, BarcodeHeight);
g.FillRectangle(witeBrush, re2);
currentLocation += weight;
}
} /// <summary>
/// 显示条形码和文字
/// </summary>
/// <param name="g"></param>
/// <param name="rects"></param>
public void DrawBarcode(Graphics g, Rectangle rects)
{
SizeF fsize = g.MeasureString(BarcodeText, this.footerFont); Rectangle b = rects;
b.Y = rects.Y + rects.Height - (int)fsize.Height;
b.X = rects.X + (rects.Width - (int)fsize.Width) / 2;
b.Height = (int)fsize.Height;
DrawText(BarcodeText, g, b);
//BarCode
Rectangle m = new Rectangle();
m = rects;
m.Height = rects.Height - b.Height;
this.BarcodeHeight = m.Height;
DrawBitmap(g, m);
} /// <summary>
/// 绘制条形码 无文字
/// </summary>
/// <param name="g"></param>
/// <param name="rects"></param>
public void DrawBarBit(Graphics g, Rectangle rects)
{
SizeF fsize = g.MeasureString(BarcodeText, this.footerFont); Rectangle b = rects;
b.Y = rects.Y + rects.Height - (int)fsize.Height;
b.X = rects.X + (rects.Width - (int)fsize.Width) / 2;
b.Height = (int)fsize.Height;
//DrawText(BarcodeText, g, b);
//BarCode
Rectangle m = new Rectangle();
m = rects;
m.Height = rects.Height - b.Height;
this.BarcodeHeight = m.Height;
DrawBitmap(g, m);
}
/// <summary>
/// 文本显示
/// </summary>
/// <param name="text"></param>
/// <param name="g"></param>
/// <param name="rects"></param>
protected void DrawText(string text, Graphics g, Rectangle rects)
{
g.DrawString(text, this.footerFont, Brushes.Black, rects);
} }
}
具体码表好像当时是从CodeProject里找到的。
graphic.DrawString("*" + dt.Rows[k]["TaskID"].ToString().Trim() + "*", new Font("C39HrP48DlTt", 50, FontStyle.Regular), brushMain, new Rectangle(XLeft + j * 270, TopNow + i * 152 + 30, 400, FontSize));
自己换成39字体搞定了 谢谢各位了