在C#中设置打印机纸盘问题 [英] Issue Setting Printer Tray in C#

查看:128
本文介绍了在C#中设置打印机纸盘问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我创建了一个生成条形码的表单,用户可以通过组合框从默认打印机中选择要使用的打印机纸盒,旁路纸盒最好,因为条形码需要打印在标签上.

该代码有效...但是我发现,如果用户首先尝试从我们的应用程序中打印出条形码,那么所选的打印机纸盘将被忽略.但是,如果用户打开MS Word,然后将打印机托盘设置为旁路并打印文档,然后返回尝试再次将条形码打印到旁路打印机,就可以了!

是否有人有任何想法,看来无论出于何种原因,打印机托盘都被第一次忽略了.打印机是Xerox Workcentre 5645,我在代码中使用PrintDocument命令.

谢谢,

格雷厄姆


感谢您的答复,代码的第一部分显示了我设置组合框的位置:

Hi all,

I have created a form which produces barcodes, the user can select which printer tray from the default printer to use via a combo box, the bypass tray is best as the barcodes need to be printed on labels.

This code works ... but I have found that if a user tries to print out barcodes from our application as the first thing they do then the selected printer tray is ignored. If, however, the user opens MS Word and then sets the printer tray there to be bypass and prints off a document then returning to try and print barcodes again to the bypass printer works!!

Does anybody have any ideas, it appears that for whatever reason the printer tray is ignored the first time. The printer is a Xerox Workcentre 5645 and I''m using the PrintDocument command in my code.

Thanks,

Graham


Thanks for your response, the first section of code shows where I set the combo box up:

PrintDocument printDoc1 = new PrintDocument();
comboPaperSource.DisplayMember = "SourceName";
PaperSource pkSource;
for (int i = 0; i < printDoc1.PrinterSettings.PaperSources.Count; i++)
{
pkSource = printDoc1.PrinterSettings.PaperSources[i];
comboPaperSource.Items.Add(pkSource);
}



然后,我将组合框值传递到一个单独的代码文件中



I then pass the combo-box value into a separate code file

BarcodePrinter tmpbcp = new BarcodePrinter(txtBarcodeData.Text, comboPaperSource.SelectedIndex);



最后,下面的代码是我设置papersource的地方



Finally the code below is where I set the papersource

PrintDocument tmpprndoc = new PrintDocument();
tmpprndoc.DefaultPageSettings.PaperSource =
tmpprndoc.PrinterSettings.PaperSources[m_PrinterTray];



有趣的是,此代码仅在用户以其在计算机上的第一时间运行时才起作用!



The interesting thing is that this codes works just not when the user runs as the first thing they do on their machine!

推荐答案

我看不到明显的问题,但我会亲自执行我的代码,如下所示...

I cannot see an obvious problem but I would personally do my code as follows...

PrintDocument printDoc1 = new PrintDocument();
comboPaperSource.DisplayMember = "SourceName";

foreach(PaperSource ps in print.PrinterSettings.PaperSources)
    comboPaperSource.Items.Add(ps.SourceName);



然后将字符串值传递给BarcodePrinter类:



Then pass string value to BarcodePrinter class:

BarcodePrinter tmpbcp = new BarcodePrinter(txtBarcodeData.Text, comboPaperSource.Text);
//this sets variable _selectedPaperSource in BarcodePrinter class



然后设置纸张来源:



Then set paper source:

PrintDocument tmpprndoc = new PrintDocument();
tmpprndoc.DefaultPageSettings.PaperSource.SourceName = _selectedPaperSource;



也许您的问题与纸张来源索引有关,或者完全不同.您应该进行一些调试,使用消息框显示传递给BarcodePrinter类的PaperSource.Source名称,以及将其分配给tmpprndoc之后使用的名称(因此在打印前测试tmpprndoc.DefaultPageSettings.PaperSource.SourceName).

希望能以某种方式提供帮助



perhaps your issue is something to do with the paper source index, or maybe something complete different. You should do some debugging, use a Message box to show PaperSource.Source name that you pass to the BarcodePrinter class and also the one that is used after you assign it to tmpprndoc (so test tmpprndoc.DefaultPageSettings.PaperSource.SourceName before you print)

hope that helps in some way


您好,

我使用此代码更改了代码中的打印机托盘,也许可以帮到您.

Hello,

I used this code to change the printer tray in the code, maybe it could help you.

    string _paperSource = "TRAY 2"; // Printer Tray
    string _paperName = "8x17"; // Printer paper name

//Tested code comment. The commented code was the one I tested, but when 
//I was writing the post I realized that could be done with less code.
	
    //PaperSize pSize = new PaperSize()  //Tested code :)
    //PaperSource pSource = new PaperSource(); //Tested code :)

    /// Find selected paperSource and paperName.
    foreach (PaperSource _pSource in printDoc.PrinterSettings.PaperSources)
    if (_pSource.SourceName.ToUpper() == _paperSource.ToUpper())
    {
	printDoc.DefaultPageSettings.PaperSource = _pSource;
    //pSource = _pSource; //Tested code :)
    break;
    }
    foreach (PaperSize _pSize in printDoc.PrinterSettings.PaperSizes)
    if (_pSize.PaperName.ToUpper() == _paperName.ToUpper())
    {
	printDoc.DefaultPageSettings.PaperSize = _pSize;
    //pSize = _pSize; //Tested code :)
    break;
    }
	 
    //printDoc.DefaultPageSettings.PaperSize = pSize; //Tested code :)
    //printDoc.DefaultPageSettings.PaperSource = pSource;	 //Tested code :)
	//My webPage www.grupokino.com :D


这篇关于在C#中设置打印机纸盘问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆