永发信息网

你好,请问你可以发我一份C#中调用tsc打印机的资料吗?

答案:2  悬赏:40  手机版
解决时间 2021-01-24 17:44
  • 提问者网友:人傍凄凉立暮秋
  • 2021-01-24 14:31
你好,请问你可以发我一份C#中调用tsc打印机的资料吗?
最佳答案
  • 五星知识达人网友:像个废品
  • 2021-01-24 15:42
public class Print
{
string printName;
[System.Runtime.InteropServices.DllImport("tsclib.dll")]
public static extern void windowsfont(int a, int b, int c, int d, int e, int f, string g, string h);
[System.Runtime.InteropServices.DllImport("tsclib.dll")]
public static extern void openport(string printername);
[System.Runtime.InteropServices.DllImport("tsclib.dll")]
public static extern void closeport();
[System.Runtime.InteropServices.DllImport("tsclib.dll")]
public static extern void sendcommand(string command);
[System.Runtime.InteropServices.DllImport("tsclib.dll")]
public static extern void setup(string width, string height, string speed, string density, string sensor, string vertical, string offset);
[System.Runtime.InteropServices.DllImport("tsclib.dll")]
public static extern void clearbuffer();
[System.Runtime.InteropServices.DllImport("tsclib.dll")]
public static extern void printlabel(string Set, string Copy);
[System.Runtime.InteropServices.DllImport("tsclib.dll")]
public static extern void printerfont(string x, string y, string fonttype, string rotation, string xmul, string ymul, string text);
[System.Runtime.InteropServices.DllImport("tsclib.dll")]
public static extern int barcode(string x, string y, string type, string height, string readable, string rotation, string narrow, string wide, string code);

public void testPrint()
{
openport(this.printName);
clearbuffer();
windowsfont(25, 30, 70, 0, 0, 0, "黑体", "连接成功");
printlabel("1", "1");
closeport();
}
public void printBegin()
{
openport(this.printName);
}
public void printOut()
{
clearbuffer();
windowsfont(10, 30, 50, 0, 0, 0, "黑体", "Print Font Test");
barcode("10", "150", "93", "90", "1", "0", "2", "2", "barCode");
downloadpcx("UL.PCX", "UL.PCX");
sendcommand("PUTPCX 100,400,\"UL.PCX\"");
printlabel("1", "1");
}
public void printEnd()
{
closeport();
}
}
全部回答
  • 1楼网友:duile
  • 2021-01-24 16:04
你可以通过设置你的默认打印机来保证你的默认打印机是tsc打印机,但是判断打印机是否打印成功好像很难做到,因为windows系统是后台打印,前台不好控制,不象dos系统,更何况卡纸、串行、没墨(包括色带)等现象根本无法用软件来判断。还是在程序中作个提示吧,由操作者判断是否打印成功,然后再根据操作者选择的结果作相应的处理。连windows里面的打印测试页都会问你打印是否正确,如果它能确定的还要多此一问吗? using system.management; private const string _classname = "select * from win32_printer"; #region 设置默认打印机 void setdefaultprinter(string printername) { managementobjectsearcher query = new managementobjectsearcher(_classname); querycollection = query.get(); foreach (managementobject mo in querycollection) { if (string.compare(mo["name"].tostring(), printername, true) == 0) { mo.invokemethod("setdefaultprinter", null); break; } } } #endregion #region 打印机是否存在 bool isprintexists(string printername) { foreach (string pname in system.drawing.printing.printersettings.installedprinters) { if (pname == printername) { return true; } } return false; } #endregion
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯