Margins Klasa

Definicja

Określa wymiary marginesów drukowanej strony.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
Dziedziczenie
Margins
Atrybuty
Implementuje

Przykłady

W tym przykładzie System.Drawing.Printingnależy użyć System.IO przestrzeni nazw ,i.System.DrawingUse the System.Drawing, System.Drawing.Printing, and System.IO namespaces for this example.

Poniższy przykład kodu ustawia domyślne ustawienia strony dla dokumentu na marginesy 1 cala po każdej stronie.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
   

Uwagi

Klasa jest używana do manipulowania szerokością marginesów w PageSettings i PrintController. MarginsThe Margins class is used to manipulate the width of margins in PageSettings and PrintController. MarginsConverterjest deskryptorem typu dla tej klasy.MarginsConverter is the type descriptor for this class.

Left, Right, Top iBottom są właściwościami, które definiują marginesy.Left, Right, Top, and Bottom are properties that define the margins. Clonetworzy identyczny Margins.Clone creates an identical Margins. EqualsOkreśla, czy inny obiekt ma takie same wymiary jak Margins.Equals determines if another object has the same dimensions as a Margins.

Aby uzyskać więcej informacji o drukowaniu, System.Drawing.Printing Zobacz Omówienie przestrzeni nazw.For more information about printing, see the System.Drawing.Printing namespace overview.

Konstruktory

Margins()

Inicjuje nowe wystąpienie Margins klasy z marginesami o szerokości 1 cala.Initializes a new instance of the Margins class with 1-inch wide margins.

Margins(Int32, Int32, Int32, Int32)

Inicjuje nowe wystąpienie Margins klasy z określonym marginesem w lewo, w prawo, u góry i u dołu.Initializes a new instance of the Margins class with the specified left, right, top, and bottom margins.

Właściwości

Bottom

Pobiera lub ustawia dolny margines w postaci setnych cala.Gets or sets the bottom margin, in hundredths of an inch.

Left

Pobiera lub ustawia szerokość lewego marginesu (w setkach cala).Gets or sets the left margin width, in hundredths of an inch.

Right

Pobiera lub ustawia szerokość prawego marginesu (w setkach cala).Gets or sets the right margin width, in hundredths of an inch.

Top

Pobiera lub ustawia szerokość górnego marginesu (w setkach cala).Gets or sets the top margin width, in hundredths of an inch.

Metody

Clone()

Pobiera duplikat tego obiektu, składowej przez członka.Retrieves a duplicate of this object, member by member.

Equals(Object)

Porównuje Margins ten sposób z Object określonym, aby określić, czy mają one te same wymiary.Compares this Margins to the specified Object to determine whether they have the same dimensions.

GetHashCode()

Oblicza i Pobiera kod skrótu w oparciu o szerokość lewego, prawego, górnego i dolnego marginesu.Calculates and retrieves a hash code based on the width of the left, right, top, and bottom margins.

GetType()

Type Pobiera bieżące wystąpienie.Gets the Type of the current instance.

(Odziedziczone po Object)
MemberwiseClone()

Tworzy skróconą kopię bieżącego Objectelementu.Creates a shallow copy of the current Object.

(Odziedziczone po Object)
ToString()

Margins Konwertuje na ciąg.Converts the Margins to a string.

Operatory

Equality(Margins, Margins)

Porównuje Margins dwa, aby określić, czy mają one te same wymiary.Compares two Margins to determine if they have the same dimensions.

Inequality(Margins, Margins)

Porównuje Margins dwa, aby określić, czy mają one nierówną szerokość.Compares two Margins to determine whether they are of unequal width.

Dotyczy

Zobacz też