PrintPageEventArgs.HasMorePages 屬性
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
取得或設定值,指出是否應該列印其他頁面。
public:
property bool HasMorePages { bool get(); void set(bool value); };
public bool HasMorePages { get; set; }
member this.HasMorePages : bool with get, set
Public Property HasMorePages As Boolean
屬性值
如果應該列印其他頁面,則為 true
,否則為 false
。 預設為 false
。
範例
下列程式代碼範例假設 Button 已在 上建立具名 printButton
和 PrintDocument 具名 pd
的 Form。 請確定 Click 的 事件與 printButton_Click
方法相關聯,且 PrintPage 的 PrintDocument 事件與範例中的 方法相關聯pd_PrintPage
Button。 範例 printButton_Click
中的 方法會呼叫 Print 引發 PrintPage 事件的方法,並列印 方法中指定的 pd_PrintPage
.bmp 檔案。 若要執行此範例,請將路徑變更為您要列印的點陣圖。
針對此範例, System.Drawing請使用、 System.Drawing.Printing和 System.Windows.Forms 命名空間。
private:
// Specifies what happens when the user clicks the Button.
void printButton_Click( Object^ /*sender*/, EventArgs^ /*e*/ )
{
try
{
pd->Print();
}
catch ( Exception^ ex )
{
MessageBox::Show( "An error occurred while printing", ex->ToString() );
}
}
// Specifies what happens when the PrintPage event is raised.
void pd_PrintPage( Object^ /*sender*/, PrintPageEventArgs^ ev )
{
// Draw a picture.
ev->Graphics->DrawImage( Image::FromFile( "C:\\My Folder\\MyFile.bmp" ),
ev->Graphics->VisibleClipBounds );
// Indicate that this is the last page to print.
ev->HasMorePages = false;
}
// Specifies what happens when the user clicks the Button.
private void printButton_Click(object sender, EventArgs e)
{
try
{
// Assumes the default printer.
pd.Print();
}
catch(Exception ex)
{
MessageBox.Show("An error occurred while printing", ex.ToString());
}
}
// Specifies what happens when the PrintPage event is raised.
private void pd_PrintPage(object sender, PrintPageEventArgs ev)
{
// Draw a picture.
ev.Graphics.DrawImage(Image.FromFile("C:\\My Folder\\MyFile.bmp"), ev.Graphics.VisibleClipBounds);
// Indicate that this is the last page to print.
ev.HasMorePages = false;
}
' Specifies what happens when the user clicks the Button.
Private Sub printButton_Click(sender As Object, e As EventArgs) _
Handles printButton.Click
Try
pd.Print()
Catch ex As Exception
MessageBox.Show("An error occurred while printing", _
ex.ToString())
End Try
End Sub
' Specifies what happens when the PrintPage event is raised.
Private Sub pd_PrintPage(sender As Object, ev As PrintPageEventArgs) _
Handles pd.PrintPage
' Draw a picture.
ev.Graphics.DrawImage(Image.FromFile("C:\My Folder\MyFile.bmp"), _
ev.Graphics.VisibleClipBounds)
' Indicate that this is the last page to print.
ev.HasMorePages = False
End Sub
如需示範如何使用 HasMorePages的另一個範例,請參閱 How to: Print a Multi-Page Text File in Windows Forms。