0
using (PrintDialog printDialog1 = new PrintDialog())
{
   if (printDialog1.ShowDialog() == DialogResult.OK)
   {
       System.Diagnostics.ProcessStartInfo info = new System.Diagnostics.ProcessStartInfo(saveAs.ToString());
       info.Arguments = "\"" + printDialog1.PrinterSettings.PrinterName + "\"";
       info.CreateNoWindow = true;
       info.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
       info.UseShellExecute = true;
       info.Verb = "PrintTo";
       System.Diagnostics.Process.Start(info);
   }
}

上記のコードは正常に動作します。最初に Word 文書をプレビューできるようにコードを変更する方法がわかりません。

4

1 に答える 1

1

さて、私は家に帰ってから昨夜これに取り組みました、そして私はそれを理解したと信じています. 完璧ではありませんが、正しい方向に進むことができますところで、このための簡単なWinFormsアプリを作成しました。必要に応じてコードを編集する必要があります。

コード:

namespace WindowsFormsApplication1
{
using System;
using System.Drawing;
using System.Windows.Forms;
using System.IO;

public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();
    }

    private void button1_Click(object sender, EventArgs e)
    {
        System.Drawing.Printing.PrintDocument doc = new System.Drawing.Printing.PrintDocument();
        PrintPreviewDialog dlg = new PrintPreviewDialog();
        dlg.Document = doc;
        doc.PrintPage += new System.Drawing.Printing.PrintPageEventHandler(this.PrintPage);
        dlg.ShowDialog();
    }

    private void PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
    {
        try
        {
            string fileName = @"C:\Users\brmoore\Desktop\New Text Document.txt";
            StreamReader sr = new StreamReader(fileName);
            string thisIsATest = sr.ReadToEnd();
            sr.Close();
            System.Drawing.Font printFont = new System.Drawing.Font("Arial", 14);
            e.Graphics.DrawString(thisIsATest, printFont, Brushes.Black, 100, 100);
        }

        catch (Exception exc)
        {
            MessageBox.Show(exc.ToString());
        }
    }
}

}

于 2013-01-24T21:58:56.000 に答える