Margins.Right 属性

定义

获取或设置右边距宽度(以百分之一英寸为单位)。

public:
 property int Right { int get(); void set(int value); };
public int Right { get; set; }
member this.Right : int with get, set
Public Property Right As Integer

属性值

右边距宽度(以百分之一英寸为单位)。

例外

Right 属性被设置为一个小于 0 的值。

示例

对于此示例, System.Drawing请使用 、 System.Drawing.PrintingSystem.IO 命名空间。

下面的代码示例将文档的默认页面设置设置为宽度为 1 英寸的左右边距,以及宽度为 1.5 英寸的上边距和下边距。

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;
         
         // Set the left and right margins to 1 inch.
         pd->DefaultPageSettings->Margins->Left = 100;
         pd->DefaultPageSettings->Margins->Right = 100;
         
         // Set the top and bottom margins to 1.5 inches.
         pd->DefaultPageSettings->Margins->Top = 150;
         pd->DefaultPageSettings->Margins->Bottom = 150;
         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;

      // Set the left and right margins to 1 inch.
      pd.DefaultPageSettings.Margins.Left = 100;
      pd.DefaultPageSettings.Margins.Right = 100;
      // Set the top and bottom margins to 1.5 inches.
      pd.DefaultPageSettings.Margins.Top = 150;
      pd.DefaultPageSettings.Margins.Bottom = 150;

      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
               
            ' Set the left and right margins to 1 inch.
            pd.DefaultPageSettings.Margins.Left = 100
            pd.DefaultPageSettings.Margins.Right = 100
            ' Set the top and bottom margins to 1.5 inches.
            pd.DefaultPageSettings.Margins.Top = 150
            pd.DefaultPageSettings.Margins.Bottom = 150
               
            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

注解

如果以毫米为单位测量边距,请将所需的边距宽度(以毫米为单位)乘以 3.937,以确定以百分之一英寸为单位的正确度量。 例如,如果希望边距为 25mm,则乘以 3.937,结果为向下舍入 98。 然后将相应的 Margins 成员设置为 98。

适用于

另请参阅