Sdílet prostřednictvím


Margins Konstruktory

Definice

Inicializuje novou instanci Margins třídy .

Přetížení

Margins()

Inicializuje novou instanci Margins třídy s 1palcovým širokým okrajem.

Margins(Int32, Int32, Int32, Int32)

Inicializuje novou instanci Margins třídy se zadaným levým, pravým, horním a dolním okrajem.

Margins()

Zdroj:
Margins.cs
Zdroj:
Margins.cs
Zdroj:
Margins.cs

Inicializuje novou instanci Margins třídy s 1palcovým širokým okrajem.

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

Platí pro

Margins(Int32, Int32, Int32, Int32)

Zdroj:
Margins.cs
Zdroj:
Margins.cs
Zdroj:
Margins.cs

Inicializuje novou instanci Margins třídy se zadaným levým, pravým, horním a dolním okrajem.

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)

Parametry

left
Int32

Levý okraj, setiny palce.

right
Int32

Pravý okraj, setiny palce.

top
Int32

Horní okraj, setiny palce.

bottom
Int32

Dolní okraj, setiny palce.

Výjimky

Hodnota parametru left je menší než 0.

-nebo-

Hodnota parametru right je menší než 0.

-nebo-

Hodnota parametru top je menší než 0.

-nebo-

Hodnota parametru bottom je menší než 0.

Příklady

V tomto příkladu System.Drawingpoužijte obory názvů , System.Drawing.Printinga System.IO .

Následující příklad kódu nastaví výchozí nastavení stránky dokumentu na okraje o šířce 1 palce na každé straně.

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

Platí pro