| 发表于:2007-03-27 21:55:03 楼主 |
using system; using system.drawing; using system.collections; using system.componentmodel; using system.windows.forms; using system.data; using terminal.api; namespace he { /// <summary> /// form1 的摘要说明。 /// </summary> public class form1 : system.windows.forms.form { private system.windows.forms.textbox txtbarcode1; private dcdevent dcdevent; public static dcdhandle hdcd; private string dcddata = string.empty; public form1() { initializecomponent(); dcdrequesttype reqtype = (dcdrequesttype)1 ¦ dcdrequesttype.postrecurring ; dcdevent = new dcdevent( form1.hdcd, reqtype); dcdevent.scanned += new dcdscanned(dcdevent_scanned); //this.closing += new canceleventhandler(acn_closing); this.activated += new eventhandler(cashregister_activated); } void cashregister_activated(object sender,eventargs e) { if(dcdevent == null) { dcdrequesttype reqtype = (dcdrequesttype)1 ¦ dcdrequesttype.postrecurring ; dcdevent = new dcdevent( form1.hdcd, reqtype); dcdevent.scanned += new dcdscanned(dcdevent_scanned); } } //打开扫描头 private void dcdevent_scanned(object sender, dcdeventargs e) { codeid cid = codeid.nodata; dcddata = string.empty; try { dcddata = form1.hdcd.readstring(e.requestid, ref cid); } catch(exception) { messagebox.show( "扫描出错 "); return; } if(dcddata.length != 0) invoke(new eventhandler(gobackmain)); } private void gobackmain(object sender,eventargs e) { //dcddata = dcddata.trimend(new char[]{ '\r ', '\n ', ' ', ' '}); dcddata = dcddata.trimstart(new char[]{(char)2,(char)3}); dcddata = dcddata.trimend(new char[]{ '\r ', '\n ', ' ', ' ',(char)2,(char)3}); if(txtbarcode1.focused) { txtbarcode1.text = dcddata; dcddata = string.empty; //this.getbarcode( txtbarcode1.text.trim()); } } /// <summary> /// 清理所有正在使用的资源。 /// </summary> protected override void dispose( bool disposing ) { base.dispose( disposing ); } #region windows 窗体设计器生成的代码 /// <summary> /// 设计器支持所需的方法 - 不要使用代码编辑器修改 /// 此方法的内容。 /// </summary> private void initializecomponent() { this.txtbarcode1 = new system.windows.forms.textbox(); // // txtbarcode1 // this.txtbarcode1.location = new system.drawing.point(24, 32); this.txtbarcode1.multiline = true; this.txtbarcode1.size = new system.drawing.size(368, 256); this.txtbarcode1.text = " "; // // form1 // this.controls.add(this.txtbarcode1); this.text = "form1 "; } #endregion /// <summary> /// 应用程序的主入口点。 /// </summary> static void main() { application.run(new form1()); } } } 未处理的“system.nullreferenceexception”类型的异常出现在 terminal.api.dll 中。 里面的api是绝对没用问题的!有做扫描枪程序的朋友帮看看吗? 我这是写的一psc的扫描枪打开扫描头,然后获得条码显示到textbox上! 跪求! |
|
|
|
|