PrintDocument.QueryPageSettings 事件
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
在 PrintPage 事件的紧面前发生。
public:
event System::Drawing::Printing::QueryPageSettingsEventHandler ^ QueryPageSettings;
public event System.Drawing.Printing.QueryPageSettingsEventHandler QueryPageSettings;
member this.QueryPageSettings : System.Drawing.Printing.QueryPageSettingsEventHandler
Public Custom Event QueryPageSettings As QueryPageSettingsEventHandler
事件类型
示例
如果打印机支持,下面的代码示例将打印具有第一页颜色的文档。 该示例要求 PrintDocument 已创建名为 的 printDoc
变量,并 PrintPage 处理 和 QueryPageSettings 事件。 在 事件中PrintPage打印每个页面后,变量currentPageNumber
将递增,该事件未显示。
对于此示例, System.Drawing 请使用 和 System.Drawing.Printing 命名空间。
private:
void MyButtonPrint_OnClick( Object^ sender, System::EventArgs^ e )
{
// Set the printer name and ensure it is valid. If not, provide a message to the user.
printDoc->PrinterSettings->PrinterName = "\\mynetworkprinter";
if ( printDoc->PrinterSettings->IsValid )
{
// If the printer supports printing in color, then override the printer's default behavior.
if ( printDoc->PrinterSettings->SupportsColor )
{
// Set the page default's to not print in color.
printDoc->DefaultPageSettings->Color = false;
}
// Provide a friendly name, set the page number, and print the document.
printDoc->DocumentName = "My Presentation";
currentPageNumber = 1;
printDoc->Print();
}
else
{
MessageBox::Show( "Printer is not valid" );
}
}
void MyPrintQueryPageSettingsEvent( Object^ sender, QueryPageSettingsEventArgs^ e )
{
// Determines if the printer supports printing in color.
if ( printDoc->PrinterSettings->SupportsColor )
{
// If the printer supports color printing, use color.
if ( currentPageNumber == 1 )
{
e->PageSettings->Color = true;
}
}
}
private void MyButtonPrint_OnClick(object sender, System.EventArgs e)
{
// Set the printer name and ensure it is valid. If not, provide a message to the user.
printDoc.PrinterSettings.PrinterName = "\\mynetworkprinter";
if (printDoc.PrinterSettings.IsValid) {
// If the printer supports printing in color, then override the printer's default behavior.
if (printDoc.PrinterSettings.SupportsColor) {
// Set the page default's to not print in color.
printDoc.DefaultPageSettings.Color = false;
}
// Provide a friendly name, set the page number, and print the document.
printDoc.DocumentName = "My Presentation";
currentPageNumber = 1;
printDoc.Print();
}
else {
MessageBox.Show("Printer is not valid");
}
}
private void MyPrintQueryPageSettingsEvent(object sender, QueryPageSettingsEventArgs e)
{
// Determines if the printer supports printing in color.
if (printDoc.PrinterSettings.SupportsColor) {
// If the printer supports color printing, use color.
if (currentPageNumber == 1 ) {
e.PageSettings.Color = true;
}
}
}
Private Sub MyButtonPrint_OnClick(ByVal sender As Object, ByVal e As System.EventArgs)
' Set the printer name and ensure it is valid. If not, provide a message to the user.
printDoc.PrinterSettings.PrinterName = "\\mynetworkprinter"
If printDoc.PrinterSettings.IsValid Then
' If the printer supports printing in color, then override the printer's default behavior.
if printDoc.PrinterSettings.SupportsColor then
' Set the page default's to not print in color.
printDoc.DefaultPageSettings.Color = False
End If
' Provide a friendly name, set the page number, and print the document.
printDoc.DocumentName = "My Presentation"
currentPageNumber = 1
printDoc.Print()
Else
MessageBox.Show("Printer is not valid")
End If
End Sub
Private Sub MyPrintQueryPageSettingsEvent(ByVal sender As Object, ByVal e As QueryPageSettingsEventArgs)
' Determines if the printer supports printing in color.
If printDoc.PrinterSettings.SupportsColor Then
' If the printer supports color printing, use color.
If currentPageNumber = 1 Then
e.PageSettings.Color = True
End If
End If
End Sub
注解
可以使用不同的页面设置打印文档的每一页。 可以通过修改 属性的各个属性 QueryPageSettingsEventArgs.PageSettings 或将 属性设置为 PageSettings来设置页面设置。 对 PageSettings 所做的更改仅影响当前页,而不会影响文档的默认页面设置。 还可以通过将 的 属性设置为 Canceltrue
QueryPageSettingsEventArgs来取消打印作业。
若要将事件与事件处理程序相关联,请将委托的 QueryPageSettingsEventHandler 实例添加到事件。 每当事件发生时,将调用事件处理程序。 有关使用委托处理事件的详细信息,请参阅 处理和引发事件。
如果使用 QueryPageSettings 事件修改打印机设置,PrintPreviewDialog 控件的性能将不会提高,即使设置了优化配置开关也是如此。 有关详细信息,请参阅 PrintPreviewDialog 控件概述。