Бөлісу құралы:


Margins Конструкторы

Определение

Инициализирует новый экземпляр класса Margins.

Перегрузки

Margins()

Инициализирует новый экземпляр класса Margins с полями, ширина которых равна 1 дюйму.

Margins(Int32, Int32, Int32, Int32)

Инициализирует новый экземпляр класса Margins с указанными левым, правым, верхним и нижним полями.

Margins()

Исходный код:
Margins.cs
Исходный код:
Margins.cs
Исходный код:
Margins.cs

Инициализирует новый экземпляр класса Margins с полями, ширина которых равна 1 дюйму.

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

Применяется к

Margins(Int32, Int32, Int32, Int32)

Исходный код:
Margins.cs
Исходный код:
Margins.cs
Исходный код:
Margins.cs

Инициализирует новый экземпляр класса Margins с указанными левым, правым, верхним и нижним полями.

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)

Параметры

left
Int32

Левое поле в сотых долях дюйма.

right
Int32

Правое поле в сотых долях дюйма.

top
Int32

Верхнее поле в сотых долях дюйма.

bottom
Int32

Нижнее поле в сотых долях дюйма.

Исключения

Значение параметра left меньше 0.

-или-

Значение параметра right меньше 0.

-или-

Значение параметра top меньше 0.

-или-

Значение параметра bottom меньше 0.

Примеры

В этом примере используйте System.Drawingпространства имен , System.Drawing.Printingи System.IO .

В следующем примере кода для параметров страницы по умолчанию для документа устанавливаются поля шириной 1 дюйм с каждой стороны.

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

Применяется к