Comparteix a través de


Margins Constructores

Definición

Inicializa una nueva instancia de la clase Margins.

Sobrecargas

Margins()

Inicializa una nueva instancia de la clase Margins con márgenes de una pulgada de ancho.

Margins(Int32, Int32, Int32, Int32)

Inicializa una nueva instancia de la clase Margins con los márgenes izquierdo, derecho, superior e inferior especificados.

Margins()

Source:
Margins.cs
Source:
Margins.cs
Source:
Margins.cs

Inicializa una nueva instancia de la clase Margins con márgenes de una pulgada de ancho.

public:
 Margins();
public Margins ();
Public Sub New ()

Se aplica a

Margins(Int32, Int32, Int32, Int32)

Source:
Margins.cs
Source:
Margins.cs
Source:
Margins.cs

Inicializa una nueva instancia de la clase Margins con los márgenes izquierdo, derecho, superior e inferior especificados.

public:
 Margins(int left, int right, int top, int bottom);
public Margins (int left, int right, int top, int bottom);
new System.Drawing.Printing.Margins : int * int * int * int -> System.Drawing.Printing.Margins
Public Sub New (left As Integer, right As Integer, top As Integer, bottom As Integer)

Parámetros

left
Int32

Margen izquierdo, en centésimas de pulgada.

right
Int32

Margen derecho, en centésimas de pulgada.

top
Int32

Margen superior, en centésimas de pulgada.

bottom
Int32

Margen inferior, en centésimas de pulgada.

Excepciones

El valor del parámetro left es menor que 0.

o bien

El valor del parámetro right es menor que 0.

o bien

El valor del parámetro top es menor que 0.

o bien

El valor del parámetro bottom es menor que 0.

Ejemplos

Use los System.Drawingespacios de nombres , System.Drawing.Printingy System.IO para este ejemplo.

En el ejemplo de código siguiente se establece la configuración de página predeterminada de un documento en márgenes de ancho de 1 pulgada en 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

Se aplica a