2009-07-27 4 views
1

プリントダイアログボックスに表示されたコピーの数、および1変更のVisual Studio 2005のために、私はデフォルトのプリンタを変更する必要がある私は、Crystal Reportsに取り組んでいます

Iのデフォルトに比べて2コピーの数以下のコードを使用してデフォルトプリンタを変更することに成功しました。

static int SetAsDefaultPrinter(string printerDevice) 
{ 
    int ret = 0; 
    try 
    { 
     string path = "win32_printer.DeviceId='" + printerDevice + "'"; 
     using (ManagementObject printer = new ManagementObject(path)) 
     { 
      ManagementBaseObject outParams = 
      printer.InvokeMethod("SetDefaultPrinter", 
      null, null); 
      ret = (int)(uint)outParams.Properties["ReturnValue"].Value;     
     } 
    } 
} 

印刷枚数を変更するにはどうすればよいですか?

+0

WinFormsまたはWebFormsを確認するだけですか? – balexandre

+0

Windowsフォーム – Rohit

+1

いつでも独自の印刷設定ダイアログをロールし、ReportDocumentでPrintToPrinterメソッドを使用できますか? –

答えて

1

.Net Frameworkは、デフォルトの印刷機能を無効にするメカニズムを提供していません。そこで、デフォルトの印刷ボタンを無効にして、Event Handlerのボタン名Print.Codeを以下に追加しました。

private void Print_Click(object sender, EventArgs e) 
{ 
    try 
    { 
     PrintDialog printDialog1 = new PrintDialog(); 
     PrintDocument pd = new PrintDocument(); 

     printDialog1.Document = pd; 
     printDialog1.ShowNetwork = true; 
     printDialog1.AllowSomePages = true; 
     printDialog1.AllowSelection = false; 
     printDialog1.AllowCurrentPage = false; 
     printDialog1.PrinterSettings.Copies = (short)this.CopiesToPrint; 
     printDialog1.PrinterSettings.PrinterName = this.PrinterToPrint; 
     DialogResult result = printDialog1.ShowDialog(); 
     if (result == DialogResult.OK) 
     { 
      PrintReport(pd); 
     } 
    } 
    catch (Exception ex) 
    { 
     MessageBox.Show(ex.Message); 
    } 
} 

private void PrintReport(PrintDocument pd) 
{ 
    ReportDocument rDoc=(ReportDocument)crvReport.ReportSource; 
    // This line helps, in case user selects a different printer 
    // other than the default selected. 
    rDoc.PrintOptions.PrinterName = pd.PrinterSettings.PrinterName; 
    // In place of Frompage and ToPage put 0,0 to print all pages, 
    // however in that case user wont be able to choose selection. 
    rDoc.PrintToPrinter(pd.PrinterSettings.Copies, false, pd.PrinterSettings.FromPage, 
     pd.PrinterSettings.ToPage); 
} 
+0

ここでデフォルトのプリンタを変更した場合、システム/その他のアプリケーションに影響はありますか? –

+0

いいえ、それはその瞬間だけ変更されます。 – Rohit

関連する問題