C#.net Windows应用程序中的打印问题 [英] print problem in C# .net windows application
问题描述
大家好
我正在C#Windows应用程序上工作,如果单击打印按钮,当我尝试运行它时,在.ini文件中的打印机路径会出现错误
下面我给出代码
Hi All
I am working on C# windows application where print button is there if I click print button the printer path in .ini file when I am trying to run it shows error
below I m giving the code
private void btnPrinter_Click(object sender, EventArgs e)
{
private printcon pObj = new printcon() //Here "printcon" is a class file//
private OdbcConnection connPrt = new OdbcConnection();
connPrt = new OdbcConnection(pObj.connection()); //Format of the initialization string does not conform to specification starting at index 0.//
PrintDocument doc = new PrintDocument();
doc.PrinterSettings.PrinterName = Convert.ToString(connPrt);
doc.PrintPage += this.doc_PrintPage;
PrintDialog dlgSettings = new PrintDialog();
dlgSettings.Document = doc;
doc.Print();
}
如果可能,请帮助
谢谢&问候
Indrajit Dasgupta
If it is possible please help
Thanks & Regards
Indrajit Dasgupta
推荐答案
我们无法从该代码中提取内容:
We cannot hep from that code:
private printcon pObj = new printcon() //Here "printcon" is a class file//
private OdbcConnection connPrt = new OdbcConnection();
connPrt = new OdbcConnection(pObj.connection()); //Format of the initialization string does not conform to specification starting at index 0.
我们不知道作为连接字符串返回的printcon.connection是什么-您尚未向我们展示.这就是ODBC系统所抱怨的.
在调试器中运行程序.在"connPrt = new OdbcConnection ..."行上放置一个断点,然后进入pObj.connection
方法.您应该能够弄清楚问题出在哪里.
We do not know what printcon.connection is returning as a connection string - you haven''t shown us that. And that is what the ODBC system is complaining about.
Run you program in the debugger. Put a breakpoint on the "connPrt = new OdbcConnection..." line, and step into the pObj.connection
method. You should be able to work out what the problem is from there.
请参阅本文,可能会对您有所帮助
不使用API打印Windows窗体 [
Refer this article, might help
Print Windows Forms w/o using API[^]
创建对象时对printcon()的调用返回错误的值可能是因为您使用pObj进行的调用不属于OdbcConnection对象,请在printcon&实例上放置断点.请参阅返回值类型.
private printcon pObj = new printcon()//这里"printcon"是一个类文件//
///在上面的行上输入断点,然后输入chk作为值类型
私有OdbcConnection connPrt =新的OdbcConnection();
connPrt =新的OdbcConnection(pObj.connection());
your call to printcon() while creating object is returning wrong value may be because of that u r call using pObj is not fall under OdbcConnection object please put breakpoint at instance of printcon & see the return value type.
private printcon pObj = new printcon() //Here "printcon" is a class file//
///put breakpoint on above line then chk for value type
private OdbcConnection connPrt = new OdbcConnection();
connPrt = new OdbcConnection(pObj.connection());
这篇关于C#.net Windows应用程序中的打印问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!