Margins Classe

Definição

Especifica as dimensões das margens de uma página impressa.

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
Herança
Margins
Atributos
Implementações

Exemplos

Use os System.Drawingnamespaces , System.Drawing.Printing, e System.IO para este exemplo.

O exemplo de código seguinte define as definições padrão de página de um documento para margens de 1 polegada de cada lado.

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

Observações

A Margins classe é usada para manipular a largura das margens em PageSettings e PrintController. MarginsConverter é o descritor de tipo para esta classe.

Left, Right, Top, e Bottom são propriedades que definem as margens. Clonecria um .Margins Equals determina se outro objeto tem as mesmas dimensões que um Margins.

Para mais informações sobre impressão, consulte a visão geral do System.Drawing.Printing namespace.

Construtores

Name Description
Margins()

Inicializa uma nova instância da Margins classe com margens de 1 polegada de largura.

Margins(Int32, Int32, Int32, Int32)

Inicializa uma nova instância da Margins classe com as margens esquerda, direita, superior e inferior especificadas.

Propriedades

Name Description
Bottom

Obtém ou define a margem inferior, em centésimos de polegada.

Left

Obtém ou define a largura da margem esquerda, em centésimos de polegada.

Right

Obtém ou define a largura da margem certa, em centésimos de polegada.

Top

Obtém ou define a largura da margem superior, em centésimos de polegada.

Métodos

Name Description
Clone()

Recupera um duplicado deste objeto, membro a membro.

Equals(Object)

Compara isto Margins com o especificado Object para determinar se têm as mesmas dimensões.

GetHashCode()

Calcula e recupera um código de hash com base na largura das margens esquerda, direita, superior e inferior.

GetType()

Obtém o Type da instância atual.

(Herdado de Object)
MemberwiseClone()

Cria uma cópia superficial do atual Object.

(Herdado de Object)
ToString()

Converte o Margins em corda.

Operadores

Name Description
Equality(Margins, Margins)

Compara dois Margins para determinar se têm as mesmas dimensões.

Inequality(Margins, Margins)

Compara dois Margins para determinar se têm largura desigual.

Aplica-se a

Ver também