Margins 类

定义

指定打印页的边距尺寸。Specifies the dimensions of the margins of a printed page.

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.PrintingSystem.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
   

注解

Margins类用于操作和中的边距宽度 PageSettings PrintControllerThe Margins class is used to manipulate the width of margins in PageSettings and PrintController. MarginsConverter 此类的类型说明符。MarginsConverter is the type descriptor for this class.

LeftRightTopBottom 是定义边距的属性。Left, Right, Top, and Bottom are properties that define the margins. Clone 创建相同的 MarginsClone creates an identical Margins. Equals 确定另一个对象是否具有与相同的维度 MarginsEquals 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()

使用 1 英寸宽的边距初始化 Margins 类的新实例。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

获取或设置下边距(以百分之一英寸为单位)。Gets or sets the bottom margin, in hundredths of an inch.

Left

获取或设置左边距宽度(以百分之一英寸为单位)。Gets or sets the left margin width, in hundredths of an inch.

Right

获取或设置右边距宽度(以百分之一英寸为单位)。Gets or sets the right margin width, in hundredths of an inch.

Top

获取或设置上边距宽度(以百分之一英寸为单位)。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()

获取当前实例的 TypeGets 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)

将两个 Margins 进行比较,以确定它们是否具有相同的尺寸。Compares two Margins to determine if they have the same dimensions.

Inequality(Margins, Margins)

将两个 Margins 进行比较,以确定它们的宽度是否不相等。Compares two Margins to determine whether they are of unequal width.

适用于

另请参阅