Margins Klasa

Definicja

Określa wymiary marginesów drukowanej strony.

public ref class Margins : ICloneable
[System.ComponentModel.TypeConverter(typeof(System.Drawing.Printing.MarginsConverter))]
public class Margins : ICloneable
[System.ComponentModel.TypeConverter(typeof(System.Drawing.Printing.MarginsConverter))]
[System.Serializable]
public class Margins : ICloneable
[System.ComponentModel.TypeConverter("System.Drawing.Printing.MarginsConverter, System.Windows.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51")]
public class Margins : ICloneable
[<System.ComponentModel.TypeConverter(typeof(System.Drawing.Printing.MarginsConverter))>]
type Margins = class
    interface ICloneable
[<System.ComponentModel.TypeConverter(typeof(System.Drawing.Printing.MarginsConverter))>]
[<System.Serializable>]
type Margins = class
    interface ICloneable
[<System.ComponentModel.TypeConverter("System.Drawing.Printing.MarginsConverter, System.Windows.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51")>]
type Margins = class
    interface ICloneable
Public Class Margins
Implements ICloneable
Dziedziczenie
Margins
Atrybuty
Implementuje

Przykłady

W tym przykładzie System.Drawingużyj przestrzeni nazw , System.Drawing.Printingi System.IO .

Poniższy przykład kodu ustawia domyślne ustawienia strony dla dokumentu na marginesy 1 cala po każdej stronie.

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 Margins służy do manipulowania szerokością marginesów w PageSettings i PrintController. MarginsConverter jest deskryptorem typu dla tej klasy.

Left, , RightTopi Bottom to właściwości definiujące marginesy. Clone tworzy identyczny Marginsobiekt . Equals określa, czy inny obiekt ma takie same wymiary jak Margins.

Aby uzyskać więcej informacji na temat drukowania, zobacz System.Drawing.Printing omówienie przestrzeni nazw.

Konstruktory

Nazwa Opis
Margins()

Inicjuje Margins nowe wystąpienie klasy z marginesami o szerokości 1 cala.

Margins(Int32, Int32, Int32, Int32)

Inicjuje nowe wystąpienie Margins klasy z określonymi lewym, prawym, górnym i dolnym marginesem.

Właściwości

Nazwa Opis
Bottom

Pobiera lub ustawia dolny margines, w setnych częściach cala.

Left

Pobiera lub ustawia szerokość lewego marginesu w setnych częściach cala.

Right

Pobiera lub ustawia prawą szerokość marginesu w setnych częściach cala.

Top

Pobiera lub ustawia szerokość górnego marginesu w setnych częściach cala.

Metody

Nazwa Opis
Clone()

Pobiera duplikat tego obiektu, składowy według elementu członkowskiego.

Equals(Object)

Porównuje to Margins z określonymi Object , aby określić, czy mają te same wymiary.

GetHashCode()

Oblicza i pobiera kod skrótu na podstawie szerokości lewego, prawego, górnego i dolnego marginesu.

GetType()

Pobiera Type bieżącego wystąpienia.

(Odziedziczone po Object)
MemberwiseClone()

Tworzy płytkią kopię bieżącego Object.

(Odziedziczone po Object)
ToString()

Konwertuje element Margins na ciąg.

Operatory

Nazwa Opis
Equality(Margins, Margins)

Porównuje dwa Margins , aby określić, czy mają te same wymiary.

Inequality(Margins, Margins)

Porównuje dwa Margins , aby określić, czy mają nierówną szerokość.

Dotyczy

Zobacz też