Marginsとは? わかりやすく解説

Margins クラス

印刷ページの余白の大きさを指定します。

名前空間: System.Drawing.Printing
アセンブリ: System.Drawing (system.drawing.dll 内)
構文構文

<SerializableAttribute> _
Public Class Margins
    Implements ICloneable
[SerializableAttribute] 
public class Margins : ICloneable
[SerializableAttribute] 
public ref class Margins : ICloneable
/** @attribute SerializableAttribute() */ 
public class Margins implements ICloneable
SerializableAttribute 
public class Margins implements ICloneable
解説解説

Margins クラスは、PageSettings と PrintController で余白の幅を操作するために使用されます。MarginsConverter は、このクラスの型記述子です。

Left、Right、Top、および Bottom は、余白を定義するプロパティです。Clone は、Margins の複製を作成します。Equals は、別のオブジェクトの大きさが Margins と同じであるどうかを判断します。

印刷の詳細については、System.Drawing.Printing 名前空間の概要のトピックを参照してください。

使用例使用例

この例では、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.Object
  System.Drawing.Printing.Margins
スレッド セーフスレッド セーフ
この型の public static (Visual Basic では Shared) メンバはすべて、スレッド セーフです。インスタンス メンバの場合は、スレッド セーフであるとは限りません。
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
Margins メンバ
System.Drawing.Printing 名前空間
PageSettings
PrintController
MarginsConverter
その他の技術情報
Windows フォームにおける印刷のサポート

Margins コンストラクタ ()


Margins コンストラクタ

Margins クラスの新しいインスタンスを初期化します。
オーバーロードの一覧オーバーロードの一覧

参照参照

関連項目

Margins クラス
Margins メンバ
System.Drawing.Printing 名前空間

Margins コンストラクタ (Int32, Int32, Int32, Int32)

Margins クラスの新しいインスタンスを指定した上下左右の余白で初期化します。

名前空間: System.Drawing.Printing
アセンブリ: System.Drawing (system.drawing.dll 内)
構文構文

例外例外
例外の種類条件

ArgumentException

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
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
Margins クラス
Margins メンバ
System.Drawing.Printing 名前空間

Margins プロパティ


パブリック プロパティパブリック プロパティ

参照参照

関連項目

Margins クラス
System.Drawing.Printing 名前空間
PageSettings
PrintController
MarginsConverter

その他の技術情報

Windows フォームにおける印刷のサポート

Margins メソッド


パブリック メソッドパブリック メソッド

プロテクト メソッドプロテクト メソッド
参照参照

関連項目

Margins クラス
System.Drawing.Printing 名前空間
PageSettings
PrintController
MarginsConverter

その他の技術情報

Windows フォームにおける印刷のサポート

Margins メンバ

印刷ページの余白の大きさを指定します。

Margins データ型で公開されるメンバを以下の表に示します。


パブリック コンストラクタパブリック コンストラクタ
パブリック プロパティパブリック プロパティ
パブリック メソッドパブリック メソッド
プロテクト メソッドプロテクト メソッド
参照参照

関連項目

Margins クラス
System.Drawing.Printing 名前空間
PageSettings
PrintController
MarginsConverter

その他の技術情報

Windows フォームにおける印刷のサポート



英和和英テキスト翻訳

英語⇒日本語日本語⇒英語

辞書ショートカット

すべての辞書の索引

「Margins」の関連用語

Marginsのお隣キーワード

   

英語⇒日本語
日本語⇒英語
   



Marginsのページの著作権

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2026 Microsoft.All rights reserved.

©2026 GRAS Group, Inc.RSS