PageSettings.Margins Свойство

Определение

Возвращает или задает поля для этой страницы.

public:
 property System::Drawing::Printing::Margins ^ Margins { System::Drawing::Printing::Margins ^ get(); void set(System::Drawing::Printing::Margins ^ value); };
public System.Drawing.Printing.Margins Margins { get; set; }
member this.Margins : System.Drawing.Printing.Margins with get, set
Public Property Margins As Margins

Значение свойства

Объект, Margins представляющий поля в сотнях дюйма для страницы. Значение по умолчанию — 1-дюймовые поля на всех сторонах.

Исключения

Принтер, названный в свойстве PrinterName , не существует.

Примеры

Следующий пример кода задает параметры страницы по умолчанию для документа поля на 1 дюйм на каждой стороне. В примере есть три предварительных требования:

  • Для печати задан путь к файлу с именем filePath переменной.

  • Определен метод с именем pd_PrintPage, который обрабатывает PrintPage событие.

  • Для переменной с именем printer принтера задано имя принтера.

System.Drawing System.Drawing.PrintingИспользуйте пространства имен и System.IO пространства имен для этого примера.

public:
   void Printing()
   {
      try
      {
         streamToPrint = gcnew StreamReader( filePath );
         try
         {
            printFont = gcnew Font( "Arial",10 );
            PrintDocument^ pd = gcnew PrintDocument;
            pd->PrintPage += gcnew PrintPageEventHandler(
               this, &Sample::pd_PrintPage );
            pd->PrinterSettings->PrinterName = printer;
            // Create a new instance of Margins with 1-inch margins.
            Margins^ margins = gcnew Margins( 100,100,100,100 );
            pd->DefaultPageSettings->Margins = margins;
            pd->Print();
         }
         finally
         {
            streamToPrint->Close();
         }
      }
      catch ( Exception^ ex ) 
      {
         MessageBox::Show( ex->Message );
      }
   }
public void Printing(){
   try{
     streamToPrint = new StreamReader (filePath);
     try{
       printFont = new Font("Arial", 10);
       PrintDocument pd = new PrintDocument(); 
       pd.PrintPage += new PrintPageEventHandler(pd_PrintPage);
       pd.PrinterSettings.PrinterName = printer;
       // Create a new instance of Margins with 1-inch margins.
       Margins margins = new Margins(100,100,100,100);
       pd.DefaultPageSettings.Margins = margins;
       pd.Print();
     } 
     finally{
       streamToPrint.Close() ;
     }
   } 
   catch(Exception ex){ 
     MessageBox.Show(ex.Message);
   }
 }
Public Sub Printing()
    Try
        streamToPrint = New StreamReader(filePath)
        Try
            printFont = New Font("Arial", 10)
            Dim pd As New PrintDocument()
            AddHandler pd.PrintPage, AddressOf pd_PrintPage
            pd.PrinterSettings.PrinterName = printer
            ' Create a new instance of Margins with 1-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(ex.Message)
    End Try
End Sub

Комментарии

При обработке PrintDocument.PrintPage события можно использовать это свойство вместе со свойством Bounds для вычисления области печати для страницы.

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

См. также раздел