/* 6 */ \ /* 7 */ \ /* 8 */ \ /* 9 */ \ /* A */ \ /* B */ \ /* C */ \ /* D */ \ /* E */ \ /* F */ \ /* G */ \ /* H */ \ /* I */ \ /* J */ \ /* K */ \ /* L */ \ /* M */ \ /* N */ \ /* O */ \ /* P */ \ /* Q */ \ /* R */ \ /* S */ \ /* T */ \ /* U */ \ /* V */ \ /* W */ \ /* X */ \ /* Y */ \ /* Z */ \ /* - */ \ /* . */ \ /*' '*/ \ /* $ */ \ /* / */ \
35
/* + */ \ /* % */ \ /* * */ \ };
sourceCode = sourceCode.ToUpper(); Bitmap objBitmap = new Bitmap(
((thickLength * 3 + narrowLength * 7) * (intSourceLength + 2)) + (leftMargin * 2),
barCodeHeight + (topMargin * 2));
Graphics objGraphics = Graphics.FromImage(objBitmap); objGraphics.FillRectangle(Brushes.White, 0, 0, objBitmap.Width, objBitmap.Height);
for (int i = 0; i < intSourceLength; i++) {
if (AlphaBet.IndexOf(sourceCode[i]) == -1 || sourceCode[i] == '*') {
objGraphics.DrawString(\
SystemFonts.DefaultFont, Brushes.Red, leftMargin, topMargin); return objBitmap; }
strEncode = string.Format(\ Code39[AlphaBet.IndexOf(sourceCode[i])]); }
strEncode = string.Format(\ int intEncodeLength = strEncode.Length; int intBarWidth;
for (int i = 0; i < intEncodeLength; i++) //绘制 Code39 barcode {
intBarWidth = strEncode[i] == '1' ? thickLength : narrowLength; objGraphics.FillRectangle(i % 2 == 0 ? Brushes.Black : Brushes.White,
leftMargin, topMargin, intBarWidth, barCodeHeight); leftMargin += intBarWidth; }
SizeF sizeF = objGraphics.MeasureString(sourceCode, font);
36
float x = (objBitmap.Width - sizeF.Width) / 2; float y = objBitmap.Height - sizeF.Height; return objBitmap; }
//在界面上显示条形码的程序段
private void ctxt_TextChanged(object sender, EventArgs e) {
string str = null;
List
if (ctxtTemp.IsFlag == \ { str = ctxtTemp.Text; break; } }
if (str.Length == 12) {
Bitmap bmp = GetCode39(str);
Graphics g = pictureBox1.CreateGraphics();
g.DrawImage(bmp, 0, 0, pictureBox1.Width, pictureBox1.Height); } }
//条形码打印的程序段
private void pd_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e) {
Graphics g = e.Graphics;
Font font = new Font(\宋?体?\ Brush brush = new SolidBrush(Color.Black);
List
g.DrawString(ctxtTemp.Text, font, brush, ctxtTemp.Location.X,
37
ctxtTemp.Location.Y); }
string str = null;
foreach (CTextBox ctxt in ctxts) {
if (ctxt.IsFlag == \ {
str = ctxt.Text; break; } }
if (str.Length == 12) {
Bitmap bmp = GetCode39(str);
Graphics gb = pictureBox1.CreateGraphics();
gb.DrawImage(bmp, 0, 0, pictureBox1.Width, pictureBox1.Height); } } }
38
39