このページの余白を取得または設定します。
Public Property Margins As Margins
[C#]
public Margins Margins {get; set;}
[C++]
public: __property Margins* get_Margins();public: __property void set_Margins(Margins*);
[JScript]
public function get Margins() : Margins;public function set Margins(Margins);
プロパティ値
ページの余白 (1/100 インチ単位) を表す Margins 。既定値は、左右上下とも、余白 1 インチです。
例外
例外の種類 | 条件 |
---|---|
InvalidPrinterException | PrinterSettings.PrinterName プロパティで指定されたプリンタが存在しません。 |
解説
PrintDocument.PrintPage イベントを処理するときに、このプロパティを Bounds プロパティと共に使用して、ページの印刷領域を計算できます。
使用例
[Visual Basic, C#, C++] ドキュメントの既定のページ設定を、左右上下とも余白 1 インチに設定する例を次に示します。この例は、次の 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
' Create a new instance of Margins with 1-inch margins.
Dim margins As New Margins(100, 100, 100, 100)
pd.DefaultPageSettings.Margins = margins
pd.Print()
Finally
streamToPrint.Close()
End Try
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub 'Printing
[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;
// Create a new instance of Margins with 1-inch margins.
Margins margins = new Margins(100,100,100,100);
pd.DefaultPageSettings.Margins = margins;
pd.Print();
}
finally{
streamToPrint.Close() ;
}
}
catch(Exception ex){
MessageBox.Show(ex.Message);
}
}
[C++]
public:
void Printing(){
try{
streamToPrint = new StreamReader (filePath);
try{
printFont = new Font(S"Arial", 10);
PrintDocument* pd = new PrintDocument();
pd->PrintPage += new PrintPageEventHandler(this, &Sample::pd_PrintPage);
pd->PrinterSettings->PrinterName = printer;
// Create a new instance of Margins with 1-inch margins.
Margins* margins = new Margins(100,100,100,100);
pd->DefaultPageSettings->Margins = margins;
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 ファミリ
参照
PageSettings クラス | PageSettings メンバ | System.Drawing.Printing 名前空間 | Margins