Margins Classe

Definizione

Specifica le dimensioni dei margini di una pagina stampata.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
Ereditarietà
Margins
Attributi
Implementazioni

Esempi

Usare gli spazi dei nomi System.Drawing, System.Drawing.Printinge System.IO per questo esempio.Use the System.Drawing, System.Drawing.Printing, and System.IO namespaces for this example.

Nell'esempio di codice seguente vengono impostate le impostazioni di pagina predefinite per un documento su margini di 1 pollice su ogni lato.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
   

Commenti

La classe Margins viene utilizzata per modificare la larghezza dei margini in PageSettings e PrintController.The Margins class is used to manipulate the width of margins in PageSettings and PrintController. MarginsConverter è il descrittore di tipo per questa classe.MarginsConverter is the type descriptor for this class.

Left, Right, Tope Bottom sono proprietà che definiscono i margini.Left, Right, Top, and Bottom are properties that define the margins. Clone crea un Marginsidentico.Clone creates an identical Margins. Equals determina se un altro oggetto ha le stesse dimensioni di un Margins.Equals determines if another object has the same dimensions as a Margins.

Per ulteriori informazioni sulla stampa, vedere Cenni preliminari sullo spazio dei nomi System.Drawing.Printing.For more information about printing, see the System.Drawing.Printing namespace overview.

Costruttori

Margins()

Inizializza una nuova istanza della classe Margins con margini pari a 1 pollice.Initializes a new instance of the Margins class with 1-inch wide margins.

Margins(Int32, Int32, Int32, Int32)

Inizializza una nuova istanza della classe Margins con i margini sinistro, destro, superiore e inferiore specificati.Initializes a new instance of the Margins class with the specified left, right, top, and bottom margins.

Proprietà

Bottom

Ottiene o imposta il margine inferiore in centesimi di pollice.Gets or sets the bottom margin, in hundredths of an inch.

Left

Ottiene o imposta la larghezza del margine sinistro, in centesimi di pollice.Gets or sets the left margin width, in hundredths of an inch.

Right

Ottiene o imposta la larghezza del margine destro, in centesimi di pollice.Gets or sets the right margin width, in hundredths of an inch.

Top

Ottiene o imposta la larghezza del margine superiore, in centesimi di pollice.Gets or sets the top margin width, in hundredths of an inch.

Metodi

Clone()

Recupera un duplicato di questo oggetto, membro dopo membro.Retrieves a duplicate of this object, member by member.

Equals(Object)

Confronta la classe Margins con l'oggetto Object specificato per determinare se hanno le stesse dimensioni.Compares this Margins to the specified Object to determine whether they have the same dimensions.

GetHashCode()

Calcola e recupera codice hash basato sulla larghezza dei margini sinistro, destro, superiore e inferiore.Calculates and retrieves a hash code based on the width of the left, right, top, and bottom margins.

GetType()

Ottiene l'oggetto Type dell'istanza corrente.Gets the Type of the current instance.

(Ereditato da Object)
MemberwiseClone()

Crea una copia superficiale dell'oggetto Object corrente.Creates a shallow copy of the current Object.

(Ereditato da Object)
ToString()

Converte la classe Margins in una stringa.Converts the Margins to a string.

Operatori

Equality(Margins, Margins)

Confronta due classi Margins per determinare se hanno le stesse dimensioni.Compares two Margins to determine if they have the same dimensions.

Inequality(Margins, Margins)

Confronta due classi Margins per determinare se hanno una larghezza diversa.Compares two Margins to determine whether they are of unequal width.

Si applica a

Vedi anche