2009-05-11 9 views
0

Quelqu'un sait comment obtenir tout cela dans une application C# qui conduit l'utilisateur à un écran de dialogue d'impression? Ce que je veux dire est la suivante:
Dans l'interface graphique, l'utilisateur sélectionne un document, fait un clic droit sur le document, choisit Imprimer. Au lieu d'imprimer immédiatement le document, le dialogue d'impression apparaît.Excel, Word, PDFs et les dialogues d'impression PowerPoint

Quelqu'un connaît la syntaxe pour tout cela? J'ai essayé d'utiliser tous les interops pour les applications MS Office et d'essayer la méthode d'impression ... mais pas de chance.

Quelqu'un peut-il me fournir un code? Je suis sérieusement à ce sujet pour HEURES et ne peux pas arriver à une chose.

+0

Pourriez-vous être plus précis au sujet de votre scénario? Où les utilisateurs sélectionnent-ils un document Office? Dans l'explorateur? Dans votre propre application? Avez-vous déjà regardé la collection 'Application.Dialogs'? –

+0

J'ai un formulaire UI Win distinct qui montre une arborescence de tous mes documents. Je suis nouveau à C# donc j'ai besoin de toute l'aide que je peux obtenir! – yeahumok

Répondre

0

Peut-être voir ce précédent Q & A: send-document-to-printer-with-c#

Ou, pour une application WPF qui imprime un FlowDocument:

private void DoThePrint(System.Windows.Documents.FlowDocument document) 
    { 
     // Clone the source document's content into a new FlowDocument. 
     // This is because the pagination for the printer needs to be 
     // done differently than the pagination for the displayed page. 
     // We print the copy, rather that the original FlowDocument. 
     System.IO.MemoryStream s = new System.IO.MemoryStream(); 
     TextRange source = new TextRange(document.ContentStart, document.ContentEnd); 
     source.Save(s, DataFormats.Xaml); 
     FlowDocument copy = new FlowDocument(); 
     TextRange dest = new TextRange(copy.ContentStart, copy.ContentEnd); 
     dest.Load(s, DataFormats.Xaml); 

     // Create a XpsDocumentWriter object, implicitly opening a Windows common print dialog, 
     // and allowing the user to select a printer. 

     // get information about the dimensions of the seleted printer+media. 
     System.Printing.PrintDocumentImageableArea ia = null; 
     System.Windows.Xps.XpsDocumentWriter docWriter = System.Printing.PrintQueue.CreateXpsDocumentWriter(ref ia); 

     if (docWriter != null && ia != null) 
     { 
      DocumentPaginator paginator = ((IDocumentPaginatorSource)copy).DocumentPaginator; 

      // Change the PageSize and PagePadding for the document to match the CanvasSize for the printer device. 
      paginator.PageSize = new Size(ia.MediaSizeWidth, ia.MediaSizeHeight); 
      Thickness t = new Thickness(72); // copy.PagePadding; 
      copy.PagePadding = new Thickness(
          Math.Max(ia.OriginWidth, t.Left), 
           Math.Max(ia.OriginHeight, t.Top), 
           Math.Max(ia.MediaSizeWidth - (ia.OriginWidth + ia.ExtentWidth), t.Right), 
           Math.Max(ia.MediaSizeHeight - (ia.OriginHeight + ia.ExtentHeight), t.Bottom)); 

      copy.ColumnWidth = double.PositiveInfinity; 
      //copy.PageWidth = 528; // allow the page to be the natural with of the output device 

      // Send content to the printer. 
      docWriter.Write(paginator); 
     } 

    } 
+0

Je ne suis pas sûr d'avoir besoin de code pour un FlowDocument. L'utilisateur essaiera d'imprimer le document et n'aura qu'à cliquer sur un dialogue d'impression pour pouvoir choisir son imprimante. – yeahumok

Questions connexes