Margins Margins Margins Margins Class

Definición

Especifica las dimensiones de los márgenes de una página impresa.Specifies the dimensions of the margins of a printed page.

public ref class Margins : ICloneable
[System.ComponentModel.TypeConverter(typeof(System.Drawing.Printing.MarginsConverter))]
[System.Serializable]
[System.ComponentModel.TypeConverter("System.Drawing.Printing.MarginsConverter, System.Windows.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51")]
public class Margins : ICloneable
type Margins = class
    interface ICloneable
Public Class Margins
Implements ICloneable
Herencia
MarginsMarginsMarginsMargins
Atributos
Implementaciones

Ejemplos

Use la System.Drawing, System.Drawing.Printing, y System.IO espacios de nombres para este ejemplo.Use the System.Drawing, System.Drawing.Printing, and System.IO namespaces for this example.

El ejemplo de código siguiente establece la página configuración predeterminada para un documento a los márgenes de 1 pulgada en cada lado.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
   

Comentarios

El Margins clase se utiliza para manipular el ancho de los márgenes en PageSettings y PrintController.The Margins class is used to manipulate the width of margins in PageSettings and PrintController. MarginsConverter es el descriptor de tipo para esta clase.MarginsConverter is the type descriptor for this class.

Left, Right, Top, y Bottom son propiedades que definen los márgenes.Left, Right, Top, and Bottom are properties that define the margins. Clone crea un idénticos Margins.Clone creates an identical Margins. Equals Determina si otro objeto tiene las mismas dimensiones que un Margins.Equals determines if another object has the same dimensions as a Margins.

Para obtener más información acerca de la impresión, consulte el System.Drawing.Printing información general del espacio de nombres.For more information about printing, see the System.Drawing.Printing namespace overview.

Constructores

Margins() Margins() Margins() Margins()

Inicializa una nueva instancia de la clase Margins con márgenes de una pulgada de ancho.Initializes a new instance of the Margins class with 1-inch wide margins.

Margins(Int32, Int32, Int32, Int32) Margins(Int32, Int32, Int32, Int32) Margins(Int32, Int32, Int32, Int32) Margins(Int32, Int32, Int32, Int32)

Inicializa una nueva instancia de la clase Margins con los márgenes izquierdo, derecho, superior e inferior especificados.Initializes a new instance of the Margins class with the specified left, right, top, and bottom margins.

Propiedades

Bottom Bottom Bottom Bottom

Obtiene o establece el margen inferior, en centésimas de pulgada.Gets or sets the bottom margin, in hundredths of an inch.

Left Left Left Left

Obtiene o establece el ancho del margen izquierdo, en centésimas de pulgada.Gets or sets the left margin width, in hundredths of an inch.

Right Right Right Right

Obtiene o establece el ancho del margen derecho, en centésimas de pulgada.Gets or sets the right margin width, in hundredths of an inch.

Top Top Top Top

Obtiene o establece el ancho del margen superior, en centésimas de pulgada.Gets or sets the top margin width, in hundredths of an inch.

Métodos

Clone() Clone() Clone() Clone()

Recupera un duplicado de este objeto, miembro a miembro.Retrieves a duplicate of this object, member by member.

Equals(Object) Equals(Object) Equals(Object) Equals(Object)

Compara este objeto Margins con el Object especificado para determinar si tienen las mismas dimensiones.Compares this Margins to the specified Object to determine whether they have the same dimensions.

GetHashCode() GetHashCode() GetHashCode() GetHashCode()

Calcula y recupera un código hash basándose en el ancho de los márgenes izquierdo, derecho, superior e inferior.Calculates and retrieves a hash code based on the width of the left, right, top, and bottom margins.

GetType() GetType() GetType() GetType()

Obtiene el Type de la instancia actual.Gets the Type of the current instance.

(Inherited from Object)
MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

Crea una copia superficial del objeto Object actual.Creates a shallow copy of the current Object.

(Inherited from Object)
ToString() ToString() ToString() ToString()

Convierte el objeto Margins en una cadena.Converts the Margins to a string.

Operadores

Equality(Margins, Margins) Equality(Margins, Margins) Equality(Margins, Margins) Equality(Margins, Margins)

Compara dos objetos Margins para determinar si tienen las mismas dimensiones.Compares two Margins to determine if they have the same dimensions.

Inequality(Margins, Margins) Inequality(Margins, Margins) Inequality(Margins, Margins) Inequality(Margins, Margins)

Compara dos objetos Margins para determinar si su ancho no es igual.Compares two Margins to determine whether they are of unequal width.

Se aplica a

Consulte también: