Margins Klasa

Definicja

Określa wymiary marginesów drukowanej strony.

C#
public class Margins : ICloneable
C#
[System.ComponentModel.TypeConverter("System.Drawing.Printing.MarginsConverter, System.Windows.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51")]
public class Margins : ICloneable
C#
[System.ComponentModel.TypeConverter(typeof(System.Drawing.Printing.MarginsConverter))]
public class Margins : ICloneable
C#
[System.ComponentModel.TypeConverter(typeof(System.Drawing.Printing.MarginsConverter))]
[System.Serializable]
public class Margins : 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.

C#
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);
  }
}

Uwagi

Klasa Margins służy do manipulowania szerokością marginesów w PageSettings i PrintController. MarginsConverter to deskryptor typów dla tej klasy.

Left, Right, Topi Bottom to właściwości definiujące marginesy. Clone Metoda 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

Margins()

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

Margins(Int32, Int32, Int32, Int32)

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

Właściwości

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

Clone()

Pobiera duplikat tego obiektu, składowy przez element członkowski.

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()

Type Pobiera wartość bieżącego wystąpienia.

(Odziedziczone po Object)
MemberwiseClone()

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

(Odziedziczone po Object)
ToString()

Konwertuje element Margins na ciąg.

Operatory

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

Produkt Wersje
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9

Zobacz też