英語で読む

次の方法で共有


Margins クラス

定義

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

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

この例では、 System.DrawingSystem.Drawing.Printing、および System.IO 名前空間を使用します。

次のコード例では、文書の既定のページ設定を各辺の余白を 1 インチに設定します。

C#
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);
  }
}

注釈

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

LeftRightTop、および Bottom は、余白を定義するプロパティです。 Clone は同一の を作成します MarginsEquals は、別のオブジェクトが と同じディメンションを Margins持っているかどうかを決定します。

印刷の詳細については、名前空間の概要に関するページを System.Drawing.Printing 参照してください。

コンストラクター

Margins()

Margins クラスの新しいインスタンスを 1 インチ幅の余白で初期化します。

Margins(Int32, Int32, Int32, Int32)

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

プロパティ

Bottom

下部余白を 1/100 インチ単位で取得または設定します。

Left

左端余白の幅を 1/100 インチ単位で取得または設定します。

Right

右端余白の幅を 1/100 インチ単位で取得または設定します。

Top

上部余白の幅を 1/100 インチ単位で取得または設定します。

メソッド

Clone()

オブジェクトのメンバーごとに値を取得して、複製を作成します。

Equals(Object)

指定した Margins と、この Object を比較して、大きさが同じであるかどうかを判断します。

GetHashCode()

上下左右の余白の幅に基づいて、ハッシュ コードを計算および取得します。

GetType()

現在のインスタンスの Type を取得します。

(継承元 Object)
MemberwiseClone()

現在の Object の簡易コピーを作成します。

(継承元 Object)
ToString()

Margins を文字列に変換します。

演算子

Equality(Margins, Margins)

2 つの Margins を比較して、大きさが同じであるかどうかを判断します。

Inequality(Margins, Margins)

2 つの Margins を比較して、幅が等しくないことを確認します。

適用対象

製品 バージョン
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9

こちらもご覧ください