Margins クラスの新しいインスタンスを指定した上下左右の余白で初期化します。
名前空間: System.Drawing.Printing
アセンブリ: System.Drawing (system.drawing.dll 内)
構文
'宣言
Public Sub New ( _
left As Integer, _
right As Integer, _
top As Integer, _
bottom As Integer _
)
'使用
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)
public Margins (
int left,
int right,
int top,
int bottom
)
public:
Margins (
int left,
int right,
int top,
int bottom
)
public Margins (
int left,
int right,
int top,
int bottom
)
public function Margins (
left : int,
right : int,
top : int,
bottom : int
)
パラメータ
- left
左端余白 (1/100 インチ単位)。
- right
右端余白 (1/100 インチ単位)。
- top
上部余白 (1/100 インチ単位)。
- bottom
下部余白 (1/100 インチ単位)。
例外
例外の種類 | 条件 |
---|---|
left パラメータの値が 0 未満です。 または right パラメータの値が 0 未満です。 または top パラメータの値が 0 未満です。 または bottom パラメータの値が 0 未満です。 |
使用例
この例では、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 によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。
バージョン情報
.NET Framework
サポート対象 : 2.0、1.1、1.0