我想使用文件对话框选择一个文件,然后使用该PrintDocument.Print
方法打印选定的文件。
下面是一些代码,它是我想要完成的部分实现:
using System;
using System.Drawing.Printing;
using System.IO;
using System.Windows.Forms;
namespace InstalledAndDefaultPrinters
{
class Program
{
static void Main(string[] args)
{
string filename="";
foreach (string printer in PrinterSettings.InstalledPrinters)
Console.WriteLine(printer);
var printerSettings = new PrinterSettings();
Console.WriteLine(string.Format("The default printer is: {0}", printerSettings.PrinterName));
Console.WriteLine(printerSettings.PrintFileName);
OpenFileDialog fdlg = new OpenFileDialog();
fdlg.Title = "Open File Dialog";
fdlg.InitialDirectory = @"C:\ ";
fdlg.RestoreDirectory = true;
fdlg.ShowDialog();
Console.WriteLine(fdlg.Title);
if (fdlg.ShowDialog() == DialogResult.OK)
{
filename = String.Copy(fdlg.FileName);
}
Console.WriteLine(filename);
PrintDialog printdg = new PrintDialog();
PrintDocument pd_doc = new PrintDocument();
printdg.ShowDialog();
if (printdg.ShowDialog() == DialogResult.OK)
{
正是在这一点上,我想打印选定的文件。
pd_doc.Print();
}
}
我上面的代码显然不能满足我的需要。有什么替代方法可以引导我朝着正确的方向前进?