Margins.Left 속성

정의

왼쪽 여백 너비(1/100인치)를 가져오거나 설정합니다.

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

속성 값

왼쪽 여백 너비(1/100인치)입니다.

예외

Left 속성이 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로 곱하여 100인치 단위로 올바른 측정값을 결정합니다. 예를 들어 여백이 25mm이면 3.937을 곱하고 반올림하면 결과는 98입니다. 그런 다음 적절한 Margins 멤버를 98로 설정합니다.

적용 대상

추가 정보