Margins.Right Właściwość

Definicja

Pobiera lub ustawia szerokość prawego marginesu (w setkach cala).Gets or sets the right margin width, in hundredths of an inch.

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

Wartość właściwości

Szerokość prawego marginesu (w setkach cala).The right margin width, in hundredths of an inch.

Wyjątki

Right Właściwość ma ustawioną wartość mniejszą niż 0.The Right property is set to a value that is less than 0.

Przykłady

W tym przykładzie System.Drawing.Printingnależy użyć System.IO przestrzeni nazw ,i.System.DrawingUse the System.Drawing, System.Drawing.Printing, and System.IO namespaces for this example.

Poniższy przykład kodu ustawia domyślne ustawienia strony dla dokumentu do lewego i prawego marginesu o szerokości 1 centymetra i górnego i dolnego marginesu wynoszącego 1,5 cm.The following code example sets the default page settings for a document to left and right margins of 1 inch in width, and top and bottom margins of 1.5 inches in width.

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    
   

Uwagi

W przypadku mierzenia marginesów w milimetrach pomnóż szerokość marginesu w milimetrach o 3,937, aby określić poprawność pomiaru w setnych częściach cala.If you measure margins in millimeters, multiply the margin width you want in millimeters by 3.937 to determine the correct measurement in hundredths of an inch. Na przykład jeśli chcesz mieć margines 25mm, pomnóż przez 3,937, a wynik wynosi 98 zaokrąglony w dół.For example, if you want a margin of 25mm, multiply by 3.937 and the result is 98 rounded down. Następnie należy ustawić odpowiedni Margins element członkowski na 98.You would then set the appropriate Margins member to 98.

Dotyczy

Zobacz też