印刷するすべてのページの既定値として使用されるページ設定を取得または設定します。
Public Property DefaultPageSettings As PageSettings
[C#]
public PageSettings DefaultPageSettings {get; set;}
[C++]
public: __property PageSettings* get_DefaultPageSettings();public: __property void set_DefaultPageSettings(PageSettings*);
[JScript]
public function get DefaultPageSettings() : PageSettings;public function set DefaultPageSettings(PageSettings);
プロパティ値
ドキュメントの既定のページ設定を指定する PageSettings 。
解説
DefaultPageSettings プロパティを使用して、複数の既定のページ設定を指定できます。たとえば、 PageSettings.Color プロパティは、ページをカラー印刷するかどうかを指定します。 PageSettings.Landscape プロパティは、横向きまたは縦向きの用紙方向を指定します。 PageSettings.Margins プロパティは、ページの余白を指定します。
ページごとに設定を指定するには、 PrintPage イベントまたは QueryPageSettings イベントを処理し、それぞれ PrintPageEventArgs または QueryPageSettingsEventArgs に含まれる PageSettings 引数を変更します。
メモ 印刷の開始後に DefaultPageSettings プロパティを使用してページ設定を変更しても、印刷中のページには影響を与えません。
使用例
[Visual Basic, C#, C++] ドキュメントの用紙方向を横向きに設定し、ドキュメントを印刷する例を次に示します。この例は、次の 3 つのことを前提にしています。変数 filePath
が印刷するファイルのパスに設定されていること、 PrintPage イベントを処理するメソッド pd_PrintPage
が定義されていること、変数 printer
がプリンタ名に設定されていることです。
[Visual Basic, C#, C++] この例では、 System.Drawing 、 System.Drawing.Printing 、および System.IO の各名前空間を使用します。
Public Sub Printing()
Try
streamToPrint = New StreamReader(filePath)
Try
printFont = New Font("Arial", 10)
Dim pd As New PrintDocument()
AddHandler pd.PrintPage, AddressOf pd_PrintPage
pd.PrinterSettings.PrinterName = printer
' Set the page orientation to landscape.
pd.DefaultPageSettings.Landscape = True
pd.Print()
Finally
streamToPrint.Close()
End Try
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub
[C#]
public void Printing()
{
try
{
streamToPrint = new StreamReader (filePath);
try
{
printFont = new Font("Arial", 10);
PrintDocument pd = new PrintDocument();
pd.PrintPage += new PrintPageEventHandler(pd_PrintPage);
pd.PrinterSettings.PrinterName = printer;
// Set the page orientation to landscape.
pd.DefaultPageSettings.Landscape = true;
pd.Print();
}
finally
{
streamToPrint.Close() ;
}
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
}
}
[C++]
public:
void Printing()
{
try
{
streamToPrint = new StreamReader (filePath);
try
{
printFont = new System::Drawing::Font(S"Arial", 10);
PrintDocument* pd = new PrintDocument();
pd->PrintPage += new PrintPageEventHandler(this, &Form1::pd_PrintPage);
pd->PrinterSettings->PrinterName = printer;
// Set the page orientation to landscape.
pd->DefaultPageSettings->Landscape = true;
pd->Print();
}
__finally
{
streamToPrint->Close() ;
}
}
catch(Exception* ex)
{
MessageBox::Show(ex->Message);
}
}
[JScript] JScript のサンプルはありません。Visual Basic、C#、および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン をクリックします。
必要条件
プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ
参照
PrintDocument クラス | PrintDocument メンバ | System.Drawing.Printing 名前空間 | PageSettings | PrintController | PrinterSettings