Margins クラス

定義

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

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

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

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

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

注釈

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

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 を比較して、幅が等しくないことを確認します。

適用対象

こちらもご覧ください