Margins クラス
アセンブリ: System.Drawing (system.drawing.dll 内)
構文
解説Margins クラスは、PageSettings と PrintController で余白の幅を操作するために使用されます。MarginsConverter は、このクラスの型記述子です。
Left、Right、Top、および Bottom は、余白を定義するプロパティです。Clone は、Margins の複製を作成します。Equals は、別のオブジェクトの大きさが Margins と同じであるどうかを判断します。
使用例この例では、System.Drawing、System.Drawing.Printing、および System.IO の各名前空間を使用します。
ドキュメントの既定のページ設定として、左右の余白を 1 インチに設定するコード例を次に示します。
Public Sub Printing() Try ' This assumes that a variable of type string, named filePath , ' has been set to the path of the file to print. streamToPrint = New StreamReader(filePath) Try printFont = New Font("Arial", 10) Dim pd As New PrintDocument() ' This assumes that a method, named pd_PrintPage, has been ' defined. pd_PrintPage handles the PrintPage event. AddHandler pd.PrintPage, AddressOf pd_PrintPage ' This assumes that a variable of type string, named ' printer, has been set to the printer's name. pd.PrinterSettings.PrinterName = printer ' Create a new instance of Margins with one 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("An error occurred printing the file - " & ex.Message) End Try End Sub
public void Printing() { try { /* This assumes that a variable of type string, named filePath , has been set to the path of the file to print. */ streamToPrint = new StreamReader (filePath); try { printFont = new Font("Arial", 10); PrintDocument pd = new PrintDocument(); /* This assumes that a method, named pd_PrintPage, has been defined. pd_PrintPage handles the PrintPage event. */ pd.PrintPage += new PrintPageEventHandler(pd_PrintPage); /* This assumes that a variable of type string, named printer, has been set to the printer's name. */ pd.PrinterSettings.PrinterName = printer; // Create a new instance of Margins with one inch margins. Margins margins = new Margins(100,100,100,100); pd.DefaultPageSettings.Margins = margins; pd.Print(); } finally { streamToPrint.Close() ; } } catch(Exception ex) { MessageBox.Show("An error occurred printing the file - " + ex.Message); } }
void Printing() { try { /* This assumes that a variable of type string, named filePath , has been set to the path of the file to print. */ streamToPrint = gcnew StreamReader( filePath ); try { printFont = gcnew System::Drawing::Font( "Arial",10 ); PrintDocument^ pd = gcnew PrintDocument; /* This assumes that a method, named pd_PrintPage, has been defined. pd_PrintPage handles the PrintPage event. */ pd->PrintPage += gcnew PrintPageEventHandler( this, &Sample::pd_PrintPage ); /* This assumes that a variable of type string, named printer, has been set to the printer's name. */ pd->PrinterSettings->PrinterName = printer; // Create a new instance of Margins with one inch margins. Margins^ margins = gcnew Margins( 100,100,100,100 ); pd->DefaultPageSettings->Margins = margins; pd->Print(); } finally { streamToPrint->Close(); } } catch ( Exception^ ex ) { MessageBox::Show( String::Concat( "An error occurred printing the file - ", ex->Message ) ); } }
public void Printing() { try { /* This assumes that a variable of type string, named filePath , has been set to the path of the file to print. */ streamToPrint = new StreamReader(filePath); try { printFont = new Font("Arial", 10); PrintDocument pd = new PrintDocument(); /* This assumes that a method, named pd_PrintPage, has been defined. pd_PrintPage handles the PrintPage event. */ pd.add_PrintPage(new PrintPageEventHandler(pd_PrintPage)); /* This assumes that a variable of type string, named printer, has been set to the printer's name. */ pd.get_PrinterSettings().set_PrinterName(printer); // Create a new instance of Margins with one inch margins. Margins margins = new Margins(100, 100, 100, 100); pd.get_DefaultPageSettings().set_Margins(margins); pd.Print(); } finally { streamToPrint.Close(); } } catch (System.Exception ex) { MessageBox.Show(("An error occurred printing the file - " + ex.get_Message())); } } //Printing
継承階層System.Drawing.Printing.Margins
スレッド セーフ
プラットフォームWindows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。
バージョン情報
参照Margins メンバ
System.Drawing.Printing 名前空間
PageSettings
PrintController
MarginsConverter
その他の技術情報
Windows フォームにおける印刷のサポート
Margins コンストラクタ ()
アセンブリ: System.Drawing (system.drawing.dll 内)
構文
プラットフォームWindows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。
バージョン情報
参照Margins コンストラクタ
オーバーロードの一覧| 名前 | 説明 |
|---|---|
| Margins () | Margins クラスの新しいインスタンスを 1 インチ幅の余白で初期化します。 |
| Margins (Int32, Int32, Int32, Int32) | Margins クラスの新しいインスタンスを指定した上下左右の余白で初期化します。 |
参照Margins コンストラクタ (Int32, Int32, Int32, Int32)
アセンブリ: System.Drawing (system.drawing.dll 内)
構文Dim left As Integer Dim right As Integer Dim top As Integer Dim bottom As Integer Dim instance As New Margins(left, right, top, bottom)
例外
使用例この例では、System.Drawing、System.Drawing.Printing、および System.IO の各名前空間を使用します。
ドキュメントの既定のページ設定として、左右の余白を 1 インチ幅に設定するコード例を次に示します。
Public Sub Printing() Try ' This assumes that a variable of type string, named filePath , ' has been set to the path of the file to print. streamToPrint = New StreamReader(filePath) Try printFont = New Font("Arial", 10) Dim pd As New PrintDocument() ' This assumes that a method, named pd_PrintPage, has been ' defined. pd_PrintPage handles the PrintPage event. AddHandler pd.PrintPage, AddressOf pd_PrintPage ' This assumes that a variable of type string, named ' printer, has been set to the printer's name. pd.PrinterSettings.PrinterName = printer ' Create a new instance of Margins with one 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("An error occurred printing the file - " & ex.Message) End Try End Sub
public void Printing() { try { /* This assumes that a variable of type string, named filePath , has been set to the path of the file to print. */ streamToPrint = new StreamReader (filePath); try { printFont = new Font("Arial", 10); PrintDocument pd = new PrintDocument(); /* This assumes that a method, named pd_PrintPage, has been defined. pd_PrintPage handles the PrintPage event. */ pd.PrintPage += new PrintPageEventHandler(pd_PrintPage); /* This assumes that a variable of type string, named printer, has been set to the printer's name. */ pd.PrinterSettings.PrinterName = printer; // Create a new instance of Margins with one inch margins. Margins margins = new Margins(100,100,100,100); pd.DefaultPageSettings.Margins = margins; pd.Print(); } finally { streamToPrint.Close() ; } } catch(Exception ex) { MessageBox.Show("An error occurred printing the file - " + ex.Message); } }
void Printing() { try { /* This assumes that a variable of type string, named filePath , has been set to the path of the file to print. */ streamToPrint = gcnew StreamReader( filePath ); try { printFont = gcnew System::Drawing::Font( "Arial",10 ); PrintDocument^ pd = gcnew PrintDocument; /* This assumes that a method, named pd_PrintPage, has been defined. pd_PrintPage handles the PrintPage event. */ pd->PrintPage += gcnew PrintPageEventHandler( this, &Sample::pd_PrintPage ); /* This assumes that a variable of type string, named printer, has been set to the printer's name. */ pd->PrinterSettings->PrinterName = printer; // Create a new instance of Margins with one inch margins. Margins^ margins = gcnew Margins( 100,100,100,100 ); pd->DefaultPageSettings->Margins = margins; pd->Print(); } finally { streamToPrint->Close(); } } catch ( Exception^ ex ) { MessageBox::Show( String::Concat( "An error occurred printing the file - ", ex->Message ) ); } }
public void Printing() { try { /* This assumes that a variable of type string, named filePath , has been set to the path of the file to print. */ streamToPrint = new StreamReader(filePath); try { printFont = new Font("Arial", 10); PrintDocument pd = new PrintDocument(); /* This assumes that a method, named pd_PrintPage, has been defined. pd_PrintPage handles the PrintPage event. */ pd.add_PrintPage(new PrintPageEventHandler(pd_PrintPage)); /* This assumes that a variable of type string, named printer, has been set to the printer's name. */ pd.get_PrinterSettings().set_PrinterName(printer); // Create a new instance of Margins with one inch margins. Margins margins = new Margins(100, 100, 100, 100); pd.get_DefaultPageSettings().set_Margins(margins); pd.Print(); } finally { streamToPrint.Close(); } } catch (System.Exception ex) { MessageBox.Show(("An error occurred printing the file - " + ex.get_Message())); } } //Printing
プラットフォームWindows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。
バージョン情報
参照Margins プロパティ
パブリック プロパティ| 名前 | 説明 | |
|---|---|---|
| Bottom | 下部余白を 1/100 インチ単位で取得または設定します。 |
| Left | 左端余白の幅を 1/100 インチ単位で取得または設定します。 |
| Right | 右端余白の幅を 1/100 インチ単位で取得または設定します。 |
| Top | 上部余白の幅を 1/100 インチ単位で取得または設定します。 |
参照関連項目
Margins クラスSystem.Drawing.Printing 名前空間
PageSettings
PrintController
MarginsConverter
その他の技術情報
Windows フォームにおける印刷のサポートMargins メソッド
パブリック メソッド| 名前 | 説明 | |
|---|---|---|
| Clone | オブジェクトのメンバごとに値を取得して、複製を作成します。 |
| Equals | オーバーロードされます。 オーバーライドされます。 2 つの Margins を比較して、大きさが同じであるかどうかを判断します。 |
| GetHashCode | オーバーライドされます。 上下左右の余白の幅に基づいて、ハッシュ コードを計算および取得します。 |
| GetType | 現在のインスタンスの Type を取得します。 ( Object から継承されます。) |
| op_Equality | 2 つの Margins を比較して、大きさが同じであるかどうかを判断します。 |
| op_Inequality | 2 つの Margins を比較して、幅が等しくないことを確認します。 |
| ReferenceEquals | 指定した複数の Object インスタンスが同一かどうかを判断します。 ( Object から継承されます。) |
| ToString | オーバーライドされます。 Margins を文字列に変換します。 |
プロテクト メソッド| 名前 | 説明 | |
|---|---|---|
| Finalize | Object がガベージ コレクションにより収集される前に、その Object がリソースを解放し、その他のクリーンアップ操作を実行できるようにします。 ( Object から継承されます。) |
| MemberwiseClone | 現在の Object の簡易コピーを作成します。 ( Object から継承されます。) |
参照関連項目
Margins クラスSystem.Drawing.Printing 名前空間
PageSettings
PrintController
MarginsConverter
その他の技術情報
Windows フォームにおける印刷のサポートMargins メンバ
Margins データ型で公開されるメンバを以下の表に示します。
パブリック コンストラクタ
パブリック プロパティ| 名前 | 説明 | |
|---|---|---|
| Bottom | 下部余白を 1/100 インチ単位で取得または設定します。 |
| Left | 左端余白の幅を 1/100 インチ単位で取得または設定します。 |
| Right | 右端余白の幅を 1/100 インチ単位で取得または設定します。 |
| Top | 上部余白の幅を 1/100 インチ単位で取得または設定します。 |
パブリック メソッド| 名前 | 説明 | |
|---|---|---|
| Clone | オブジェクトのメンバごとに値を取得して、複製を作成します。 |
| Equals | オーバーロードされます。 オーバーライドされます。 2 つの Margins を比較して、大きさが同じであるかどうかを判断します。 |
| GetHashCode | オーバーライドされます。 上下左右の余白の幅に基づいて、ハッシュ コードを計算および取得します。 |
| GetType | 現在のインスタンスの Type を取得します。 (Object から継承されます。) |
| op_Equality | 2 つの Margins を比較して、大きさが同じであるかどうかを判断します。 |
| op_Inequality | 2 つの Margins を比較して、幅が等しくないことを確認します。 |
| ReferenceEquals | 指定した複数の Object インスタンスが同一かどうかを判断します。 (Object から継承されます。) |
| ToString | オーバーライドされます。 Margins を文字列に変換します。 |
プロテクト メソッド| 名前 | 説明 | |
|---|---|---|
| Finalize | Object がガベージ コレクションにより収集される前に、その Object がリソースを解放し、その他のクリーンアップ操作を実行できるようにします。 (Object から継承されます。) |
| MemberwiseClone | 現在の Object の簡易コピーを作成します。 (Object から継承されます。) |
参照関連項目
Margins クラスSystem.Drawing.Printing 名前空間
PageSettings
PrintController
MarginsConverter
その他の技術情報
Windows フォームにおける印刷のサポート- Marginsのページへのリンク