Export (0) Print
Expand All

Margins.Right Property

Gets or sets the right margin, in hundredths of an inch.

[Visual Basic]
Public Property Right As Integer
[C#]
public int Right {get; set;}
[C++]
public: __property int get_Right();
public: __property void set_Right(int);
[JScript]
public function get Right() : int;
public function set Right(int);

Property Value

The right margin, in hundredths of an inch.

Exceptions

Exception Type Condition
ArgumentException The Right property is set to a value that is less than 0.

Example

[Visual Basic, C#, C++] Use the System.Drawing, System.Drawing.Printing, and System.IO namespaces for this example.

[Visual Basic, C#, C++] The following example sets the default page settings for a document to left and right margins of 1 inch, and top and bottom margins of 1.5 inches.

[Visual Basic] 
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    
   

[C#] 
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);
  }
}


[C++] 
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 System::Drawing::Font(S"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(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( S"An error occurred printing the file - ", ex->Message ));
   }
 }
 

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

See Also

Margins Class | Margins Members | System.Drawing.Printing Namespace | Left | Top | Bottom

Show:
© 2015 Microsoft