效果圖
開(kāi)發(fā)、使用環(huán)境說(shuō)明
安裝tsc_7.3.8_m-3.exe打印機(jī)驅(qū)動(dòng),安裝時(shí)選擇對(duì)應(yīng)的ttp 244 pro
將tsclib.dll復(fù)制到c:\windows\system
驅(qū)動(dòng)安裝說(shuō)明
選擇下一步
選擇安裝路徑,默認(rèn)即可,選擇下一步
選擇安裝打印機(jī),選擇下一步
選擇其他,點(diǎn)擊下一步
選擇對(duì)應(yīng)的打印機(jī)型號(hào),點(diǎn)擊下一步
選擇usb端口,點(diǎn)擊下一步
直接默認(rèn)即可,點(diǎn)擊下一步
驅(qū)動(dòng)安裝完成!
tsclib.cs代碼:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
|
using system; using system.collections.generic; using system.linq; using system.text; using system.threading.tasks; using system.runtime.interopservices; namespace windowsformsprint { public class tsclib_dll { [dllimport("tsclib.dll", entrypoint = "about")] public static extern int about(); [dllimport("tsclib.dll", entrypoint = "openport")] public static extern int openport(string printername); [dllimport("tsclib.dll", entrypoint = "barcode")] public static extern int barcode(string x, string y, string type, string height, string readable, string rotation, string narrow, string wide, string code); [dllimport("tsclib.dll", entrypoint = "clearbuffer")] public static extern int clearbuffer(); [dllimport("tsclib.dll", entrypoint = "closeport")] public static extern int closeport(); [dllimport("tsclib.dll", entrypoint = "downloadpcx")] public static extern int downloadpcx(string filename, string image_name); [dllimport("tsclib.dll", entrypoint = "formfeed")] public static extern int formfeed(); [dllimport("tsclib.dll", entrypoint = "nobackfeed")] public static extern int nobackfeed(); [dllimport("tsclib.dll", entrypoint = "printerfont")] public static extern int printerfont(string x, string y, string fonttype, string rotation, string xmul, string ymul, string text); [dllimport("tsclib.dll", entrypoint = "printlabel")] public static extern int printlabel(string set, string copy); [dllimport("tsclib.dll", entrypoint = "sendcommand")] public static extern int sendcommand(string printercommand); [dllimport("tsclib.dll", entrypoint = "setup")] public static extern int setup(string width, string height, string speed, string density, string sensor, string vertical, string offset); [dllimport("tsclib.dll", entrypoint = "windowsfont")] public static extern int windowsfont(int x, int y, int fontheight, int rotation, int fontstyle, int fontunderline, string szfacename, string content); //打開(kāi)打印機(jī)端口,并進(jìn)行相關(guān)設(shè)置 public static void openportext() { tsclib_dll.openport("tsc ttp-244 pro");//找打打印機(jī)端口 tsclib_dll.sendcommand("size 60 mm,30 mm");//設(shè)置條碼大小 tsclib_dll.sendcommand("gap 2 mm,0");//設(shè)置條碼間隙 tsclib_dll.sendcommand("speed 4");//設(shè)置打印速度 tsclib_dll.sendcommand("density 7");//設(shè)置墨汁濃度 tsclib_dll.sendcommand("derection 1");//設(shè)置相對(duì)起點(diǎn) tsclib_dll.sendcommand("reference 3 mm,3 mm");//設(shè)置偏移邊框 tsclib_dll.sendcommand("cls");//清除記憶(每次打印新的條碼時(shí)先清除上一次的打印記憶) } //打印在用車(chē)檔案二維碼 public static void printvehiclecode(string str_hetong, string str_zhengjian, string str_name) { char space = (char)(32); string codevalue = str_hetong + space + str_zhengjian; tsclib_dll.sendcommand("cls");//需要清除上一次的打印記憶 tsclib_dll.sendcommand("qrcode 260,20,h,7,a,0,m2,s7,\"" + codevalue + "\""); tsclib_dll.windowsfont(240, 100, 24, 180, 0, 0, "黑體", str_hetong); tsclib_dll.windowsfont(240, 140, 24, 180, 0, 0, "黑體", str_zhengjian); tsclib_dll.windowsfont(240, 180, 24, 180, 0, 0, "黑體", str_name); tsclib_dll.printlabel("1", "1"); } //打印財(cái)務(wù)條形碼 public static void printfinancecode(string str_date, string str_siteno, string str_sitename, string str_num, string str_name, int count) { for (int i = 0; i < count; i++) { char num = (char)(i + 65); char space = (char)(32); string value = str_date + space + str_siteno + space + str_num + space + num; string txt = str_date + space + str_sitename + space + str_num + space + str_name + space + num; tsclib_dll.sendcommand("cls");//需要清除上一次的打印記憶 tsclib_dll.barcode("40", "50", "128", "160", "0", "0", "2", "2", value); tsclib_dll.windowsfont(440, 35, 24, 180, 0, 0, "黑體", txt); tsclib_dll.printlabel("1", "1"); } } //關(guān)閉打印機(jī)端口 public static void closeportext() { tsclib_dll.closeport(); } } } |
打印二維碼:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
private void print_click(object sender, eventargs e) { try { print.enabled = false; base.dowork(doprint); print.enabled = true; } catch (exception ex) { // fileloghelper.writeinfolog(ex.tostring()); messagebox.show(ex.tostring()); } } private void doprint(object sender, eventargs e) { datagridviewselectedrowcollection rows = archivesview.selectedrows; if (rows.count <= 0) { messagebox.show("請(qǐng)先選擇數(shù)據(jù)項(xiàng)!"); return; } tsclib_dll.openportext(); foreach (datagridviewrow dr in rows) { tsclib_dll.printvehiclecode(dr.cells[1].value.tostring(), dr.cells[2].value.tostring(), dr.cells[3].value.tostring()); } tsclib_dll.closeportext(); } |
c#調(diào)用dll提示"試圖加載格式不正確的程序"解決方法
程序在32位操作系統(tǒng)上運(yùn)行正常,在64位操作系統(tǒng)上運(yùn)行讀卡功能提示”試圖加載格式不正確“。
程序在64位操作系統(tǒng)上運(yùn)行正常,在64位操作系統(tǒng)上運(yùn)行讀卡功能提示”試圖加載格式不正確“。
--------------------------------------------------------------------------------------------
點(diǎn)擊項(xiàng)目屬性,把目標(biāo)平臺(tái)any cpu 設(shè)置為x86(32位操作系統(tǒng))或者x64(64位操作系統(tǒng))
按照上面解決方案可能會(huì)有下面的問(wèn)題:
c# form繼承問(wèn)題 : 提示 無(wú)法加載基類(lèi) ;請(qǐng)確保已引用該程序集并已生成所有項(xiàng)目。
把 生成 - 目標(biāo)平臺(tái) 改成 x86或者any cpu ,重新生成一次,form可正常編輯。
所以新的解決方案是:選擇any cpu 把下面打勾的去掉
以上這篇c# tsc打印二維碼和條形碼的實(shí)現(xiàn)方法就是小編分享給大家的全部?jī)?nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持服務(wù)器之家。
原文鏈接:http://www.cnblogs.com/yechangzhong-826217795/p/7216352.html