c 如何列印條形碼

2021-09-22 22:33:34 字數 4498 閱讀 4484

1、**實現部分

//定義乙個列印文件物件

printdocument printdocument1 = new printdocument();

//開始列印

public void beginprint(string cardcode)

//初始化列印

public void printinit()

//列印的頁面

void printdocument1_printpage(object sender, printpageeventargs ev)

2、code128類

using system;

using system.collections.generic;

using system.data;

using system.drawing;

public class code128

set }

private font m_valuefont = null;

/// /// 是否顯示可見號碼 如果為null不顯示號碼

///

public font valuefont set }

private byte m_magnify = 0;

/// /// 放大倍數

///

public byte magnify set }

/// /// 條碼類別

///

public enum encode

public code128()

", "93", "111341");

m_code128.rows.add("94", "rs", "~", "94", "131141");

m_code128.rows.add("95", "us", "del", "95", "114113");

m_code128.rows.add("96", "fnc3", "fnc3", "96", "114311");

m_code128.rows.add("97", "fnc2", "fnc2", "97", "411113");

m_code128.rows.add("98", "shift", "shift", "98", "411311");

m_code128.rows.add("99", "codec", "codec", "99", "113141");

m_code128.rows.add("100", "codeb", "fnc4", "codeb", "114131");

m_code128.rows.add("101", "fnc4", "codea", "codea", "311141");

m_code128.rows.add("102", "fnc1", "fnc1", "fnc1", "411131");

m_code128.rows.add("103", "starta", "starta", "starta", "211412");

m_code128.rows.add("104", "startb", "startb", "startb", "211214");

m_code128.rows.add("105", "startc", "startc", "startc", "211232");

m_code128.rows.add("106", "stop", "stop", "stop", "2331112");

#endregion

}/// /// 獲取128圖形

///

/// 文字

/// 編碼

/// 圖形

public bitmap getcodeimage(string p_text, encode p_code,graphics g=null)

catch

_text += getvalue(p_code, p_text.substring(0, 2), ref _temp);

_textnumb.add(_temp);

p_text = p_text.remove(0, 2);

}break;

case encode.ean128:

_examine = 105;

if (!((p_text.length & 1) == 0)) throw new exception("ean128長度必須是偶數");

_textnumb.add(102);

_text += "411131";

while (p_text.length != 0)

catch

_text += getvalue(encode.code128c, p_text.substring(0, 2), ref _temp);

_textnumb.add(_temp);

p_text = p_text.remove(0, 2);

}break;

default:

if (p_code == encode.code128a)

else

while (p_text.length != 0)

break;

}if (_textnumb.count == 0) throw new exception("錯誤的編碼,無資料");

_text = _text.insert(0, getvalue(_examine)); //獲取開始位

for (int i = 0; i != _textnumb.count; i++)

_examine = _examine % 103; //獲得嚴效位

_text += getvalue(_examine); //獲取嚴效位

_text += "2331112"; //結束位

bitmap _codeimage = getimage(_text, _viewtext,g);

//getviewtext(_codeimage, _viewtext);

return _codeimage;

}/// /// 獲取目標對應的資料

///

/// 編碼

/// 數值 a b 30

/// 返回編號

/// 編碼

private string getvalue(encode p_code, string p_value, ref int p_setid)

/// /// 根據編號獲得條紋

///

///

///

private string getvalue(int p_codeid)

/// /// 獲得條碼圖形

///

/// 文字

/// 圖形

private bitmap getimage(string p_text, string sourcetext,graphics g=null)

bitmap _codeimage = new bitmap(_width+4 , (int)m_height + 12);

graphics _garphics = g;

//pen _pen;

int _lenex = 6;

int _topex = 4;

if (g == null)

for (int i = 0; i != _value.length; i++)

else

//_garphics.(_pen, new point(_lenex, 0), new point(_lenex, m_height));

_lenex += _valuenumb;

}_garphics.drawstring(sourcetext, new font("宋體", 10f), new solidbrush(color.black), new pointf(2, m_height+_topex));

if (_garphics != g)

return _codeimage;

}/// /// 顯示可見條碼文字 如果小於40 不顯示文字

///

/// 圖形

private void getviewtext(bitmap p_bitmap, string p_viewtext)

int _stary = p_bitmap.height - (int)_drawsize.height;

_graphics.fillrectangle(brushes.white, new rectangle(0, _stary, p_bitmap.width, (int)_drawsize.height));

_graphics.drawstring(p_viewtext, m_valuefont, brushes.black, 0, _stary);

}//12345678

//(105 + (1 * 12 + 2 * 34 + 3 * 56 + 4 *78)) % 103 = 47

//結果為starc +12 +34 +56 +78 +47 +end

}

c 小票印表機打條形碼 C 條形碼的生成與列印

本文主要介紹基於第三方類庫barcodex製作條形碼及列印方法 第一步 引用類庫 第二步 定義乙個列印的方法 列印條形碼方法 為printdocument物件的printpage事件提供資料 待生成條形碼的文字 條形碼寬度 條形碼高度 偏移量x 影象距列印紙左邊的距離 偏移量y 影象距列印紙頂端的距...

C 掃條形碼

需要有呼叫窗體註冊 keydown事件且屬性 keypreview true region 條件處理barcodehook barcodehook null private void mie mainfrom keydown object sender,keyeventargs e void bar...

生成條形碼 條碼申請後如何生成商品條形碼

很多小夥伴只知道商品條形碼需要申請,但是條碼申請後如何生成商品條形碼就不知道如何操作了,今天就給大家詳細介紹一下商品條形碼生成方法。咱們國家商品條形碼的型別是ean 13條碼 69開頭的國別碼,廠商識別 產品 1位校驗位 條碼申請後就會有分配的國別碼和廠商識別 產品 需要自己編輯,校驗位可由條碼生成...