Margins Класс

Определение

Задает размеры полей печатной страницы.

public ref 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
[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))>]
type Margins = class
    interface ICloneable
[<System.ComponentModel.TypeConverter(typeof(System.Drawing.Printing.MarginsConverter))>]
[<System.Serializable>]
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
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, , RightTopи 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 , чтобы определить, имеют ли они неравную ширину.

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

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