Margins クラス

定義

印刷ページの余白の大きさを指定します。Specifies the dimensions of the margins of a printed page.

public ref class Margins : ICloneable
[System.ComponentModel.TypeConverter(typeof(System.Drawing.Printing.MarginsConverter))]
[System.Serializable]
[System.ComponentModel.TypeConverter("System.Drawing.Printing.MarginsConverter, System.Windows.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51")]
public class Margins : ICloneable
type Margins = class
    interface ICloneable
Public Class Margins
Implements ICloneable
継承
Margins
属性
実装

この例System.DrawingSystem.Drawing.Printingは、 System.IO 、、およびの各名前空間を使用します。Use the System.Drawing, System.Drawing.Printing, and System.IO namespaces for this example.

次のコード例では、ドキュメントの既定のページ設定を、各辺の1インチの余白に設定します。The following code example sets the default page settings for a document to margins of 1 inch on each side.

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.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);
  }
}

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
   

注釈

クラスは、およびPageSettings PrintControllerの余白の幅を操作するために使用されます。 MarginsThe Margins class is used to manipulate the width of margins in PageSettings and PrintController. MarginsConverterは、このクラスの型記述子です。MarginsConverter is the type descriptor for this class.

Left、、 Right 、およびBottomは、余白を定義するプロパティです。 TopLeft, Right, Top, and Bottom are properties that define the margins. Clone同一Marginsのを作成します。Clone creates an identical Margins. Equals別のオブジェクトがと同じディメンションを持ってMarginsいるかどうかを判断します。Equals determines if another object has the same dimensions as a Margins.

印刷の詳細については、 System.Drawing.Printing 「名前空間の概要」を参照してください。For more information about printing, see the System.Drawing.Printing namespace overview.

コンストラクター

Margins()

Margins クラスの新しいインスタンスを 1 インチ幅の余白で初期化します。Initializes a new instance of the Margins class with 1-inch wide margins.

Margins(Int32, Int32, Int32, Int32)

Margins クラスの新しいインスタンスを指定した上下左右の余白で初期化します。Initializes a new instance of the Margins class with the specified left, right, top, and bottom margins.

プロパティ

Bottom

下部余白を 1/100 インチ単位で取得または設定します。Gets or sets the bottom margin, in hundredths of an inch.

Left

左端余白の幅を 1/100 インチ単位で取得または設定します。Gets or sets the left margin width, in hundredths of an inch.

Right

右端余白の幅を 1/100 インチ単位で取得または設定します。Gets or sets the right margin width, in hundredths of an inch.

Top

上部余白の幅を 1/100 インチ単位で取得または設定します。Gets or sets the top margin width, in hundredths of an inch.

メソッド

Clone()

オブジェクトのメンバーごとに値を取得して、複製を作成します。Retrieves a duplicate of this object, member by member.

Equals(Object)

指定した Margins と、この Object を比較して、大きさが同じであるかどうかを判断します。Compares this Margins to the specified Object to determine whether they have the same dimensions.

GetHashCode()

上下左右の余白の幅に基づいて、ハッシュ コードを計算および取得します。Calculates and retrieves a hash code based on the width of the left, right, top, and bottom margins.

GetType()

現在のインスタンスの Type を取得します。Gets the Type of the current instance.

(継承元 Object)
MemberwiseClone()

現在の Object の簡易コピーを作成します。Creates a shallow copy of the current Object.

(継承元 Object)
ToString()

Margins を文字列に変換します。Converts the Margins to a string.

演算子

Equality(Margins, Margins)

2 つの Margins を比較して、大きさが同じであるかどうかを判断します。Compares two Margins to determine if they have the same dimensions.

Inequality(Margins, Margins)

2 つの Margins を比較して、幅が等しくないことを確認します。Compares two Margins to determine whether they are of unequal width.

適用対象

こちらもご覧ください