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 используется для управления шириной полей в PageSettings и PrintController. MarginsConverter — дескриптор типа для этого класса.

Left, Right, Topи Bottom — это свойства, определяющие поля. Clone создает идентичный Marginsобъект . Equals определяет, имеет ли другой объект те же измерения, что и Margins.

Дополнительные сведения о печати см. в обзоре System.Drawing.Printing пространства имен.

Конструкторы

Margins()

Инициализирует новый экземпляр класса Margins с полями, ширина которых равна 1 дюйму.

Margins(Int32, Int32, Int32, Int32)

Инициализирует новый экземпляр класса Margins с указанными левым, правым, верхним и нижним полями.

Свойства

Bottom

Получает или задает нижнее поле в сотых долях дюйма.

Left

Получает или задает ширину левого поля в сотых долях дюйма.

Right

Получает или задает ширину правого поля в сотых долях дюйма.

Top

Получает или задает ширину верхнего поля в сотых долях дюйма.

Методы

Clone()

Почленно загружает дубликат этого объекта.

Equals(Object)

Сравнивает этот объект Margins с указанным объектом Object, чтобы определить, обладают ли они одинаковыми размерами.

GetHashCode()

Рассчитывает и извлекает хэш-код на основе ширины левого, правого, верхнего и нижнего полей.

GetType()

Возвращает объект Type для текущего экземпляра.

(Унаследовано от Object)
MemberwiseClone()

Создает неполную копию текущего объекта Object.

(Унаследовано от Object)
ToString()

Преобразует объект Margins в строку.

Операторы

Equality(Margins, Margins)

Сравнивает два объекта Margins, чтобы определить, обладают ли они одинаковыми размерами.

Inequality(Margins, Margins)

Сравнивает два объекта Margins, чтобы определить, равны ли они по ширине.

Применяется к

См. также раздел