簡體   English   中英

打印機僅打印到默認打印機

[英]Printer only prints to default printer

這是我使用的代碼(只是與打印有關的部分):

按鈕1 onclick處理程序方法:

printDialog1 = new PrintDialog();
printDialog1.AllowPrintToFile = true;
printDialog1.PrintToFile = false;
if (printDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
    PrintDocument pd = new PrintDocument();
    pd.DefaultPageSettings.PaperSize = new PaperSize("A4", 826, 1169);
    pd.PrinterSettings.PrintToFile = true;
    pd.PrintPage += new PrintPageEventHandler(pd_PrintPage);
    pd.Print();
}

和我的pd_PrintPage方法:

Bitmap bitmapCanvas = new Bitmap(1000, 1000);
Graphics g = Graphics.FromImage(bitmapCanvas);
g.Clear(Color.White);
...
some g.Draw...() stuff

...
e.Graphics.DrawImage(bitmapCanvas, A(2), A(2));
//where e is the PrintPageEventArgs defined in the method signature

我的問題的第一部分是,它不會打印到所選打印機(在打印對話框中選擇)。 僅當默認打印機時,它才會打印到打印機。 在Windows 7下它可以工作,它可以識別默認打印機,因此默認情況下,將在我單擊按鈕后出現的打印對話框的comboBox中選擇默認打印機。

我的主要問題是,這根本無法在Windows Xp下運行(不幸的是,我只能使用它)。 我很好奇為什么。 所以我不知道我是否搞砸了,或者Windows Xp不支持它。

我應該用什么來完成或糾正我的代碼?

感謝您的幫助,非常感謝! Mitulat bati

嘗試這個,

printDialog1 = new PrintDialog();
printDialog1.AllowPrintToFile = true;
printDialog1.PrintToFile = false;
if (printDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
    printDialog1.Document.DefaultPageSettings.PaperSize = new PaperSize("A4", 826, 1169);
    printDialog1.Document.PrinterSettings.PrintToFile = true;
    printDialog1.Document.PrintPage += new PrintPageEventHandler(pd_PrintPage);
    printDialog1.Document.Print();
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM