Condividi tramite


Margins Costruttori

Definizione

Inizializza una nuova istanza della classe Margins.

Overload

Margins()

Inizializza una nuova istanza della classe Margins con margini pari a 1 pollice.

Margins(Int32, Int32, Int32, Int32)

Inizializza una nuova istanza della classe Margins con i margini sinistro, destro, superiore e inferiore specificati.

Margins()

Origine:
Margins.cs
Origine:
Margins.cs
Origine:
Margins.cs

Inizializza una nuova istanza della classe Margins con margini pari a 1 pollice.

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

Si applica a

Margins(Int32, Int32, Int32, Int32)

Origine:
Margins.cs
Origine:
Margins.cs
Origine:
Margins.cs

Inizializza una nuova istanza della classe Margins con i margini sinistro, destro, superiore e inferiore specificati.

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)

Parametri

left
Int32

Margine sinistro, in centesimi di pollice.

right
Int32

Margine destro, in centesimi di pollice.

top
Int32

Margine superiore, in centesimi di pollice.

bottom
Int32

Margine inferiore, in centesimi di pollice.

Eccezioni

Il valore del parametro left è minore di 0.

-oppure-

Il valore del parametro right è minore di 0.

-oppure-

Il valore del parametro top è minore di 0.

-oppure-

Il valore del parametro bottom è minore di 0.

Esempio

Usare gli spazi dei System.Drawingnomi , System.Drawing.Printinge System.IO per questo esempio.

Nell'esempio di codice seguente le impostazioni di pagina predefinite per un documento vengono impostate sui margini di larghezza di 1 pollice su ogni lato.

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

Si applica a