如果您在Visual Studio 2005中进入以下位置(或只需按ctrl+p):
文件 ==> 打印..
你会得到一个打印对话框。我想在我的程序中也有同样的功能,但是怎么实现呢?
PrintDialog
类。下面的MSDN页面包含了描述以及一些示例代码:
PrintDialog.ShowDialog();
代码添加到其中,检查是否单击了打印按钮,如果是,则使用DocumentToPrint.Print();
进行打印。
以下是示例:private void Button1_Click(System.Object sender,
System.EventArgs e)
{
// Allow the user to choose the page range he or she would
// like to print.
PrintDialog1.AllowSomePages = true;
// Show the help button.
PrintDialog1.ShowHelp = true;
// Set the Document property to the PrintDocument for
// which the PrintPage Event has been handled. To display the
// dialog, either this property or the PrinterSettings property
// must be set
PrintDialog1.Document = docToPrint;
DialogResult result = PrintDialog1.ShowDialog();
// If the result is OK then print the document.
if (result==DialogResult.OK)
{
docToPrint.Print();
}
}
示例源代码: http://msdn.microsoft.com/zh-cn/library/system.windows.forms.printdialog.document.aspx
PrintDialog
:http://msdn.microsoft.com/en-us/library/system.windows.controls.printdialog.aspx
如果您使用的是WinForms,您也可以使用PrintDialog
:http://msdn.microsoft.com/en-us/library/system.windows.forms.printdialog.aspx
var printDialog = new PrintDialog();
printDialog.ShowDialog();
......但是打印必须由您自己完成...;-)
编辑:对于仍在使用VisualStudio2005的所有人:
PrintDialog printDialog = new PrintDialog();
printDialog.ShowDialog();
PrintDialog printDialog = new PrintDialog()
... 翻白眼 - Thorsten Dittmarvar
。在这种情况下,我是一个“有信念的人”。 :-) - Fischermaen