다음을 통해 공유


Margins 생성자

정의

Margins 클래스의 새 인스턴스를 초기화합니다.

오버로드

Margins()

1인치의 여백을 사용하여 Margins 클래스의 새 인스턴스를 초기화합니다.

Margins(Int32, Int32, Int32, Int32)

지정된 왼쪽, 오른쪽, 위쪽 및 아래쪽 여백을 사용하여 Margins 클래스의 새 인스턴스를 초기화합니다.

Margins()

Source:
Margins.cs
Source:
Margins.cs
Source:
Margins.cs

1인치의 여백을 사용하여 Margins 클래스의 새 인스턴스를 초기화합니다.

public:
 Margins();
public Margins ();
Public Sub New ()

적용 대상

Margins(Int32, Int32, Int32, Int32)

Source:
Margins.cs
Source:
Margins.cs
Source:
Margins.cs

지정된 왼쪽, 오른쪽, 위쪽 및 아래쪽 여백을 사용하여 Margins 클래스의 새 인스턴스를 초기화합니다.

public:
 Margins(int left, int right, int top, int bottom);
public Margins (int left, int right, int top, int bottom);
new System.Drawing.Printing.Margins : int * int * int * int -> System.Drawing.Printing.Margins
Public Sub New (left As Integer, right As Integer, top As Integer, bottom As Integer)

매개 변수

left
Int32

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

right
Int32

오른쪽 여백(1/100인치)입니다.

top
Int32

위쪽 여백(1/100인치)입니다.

bottom
Int32

아래쪽 여백(1/100인치)입니다.

예외

left 매개 변수 값이 0 미만인 경우

또는

right 매개 변수 값이 0 미만인 경우

또는

top 매개 변수 값이 0 미만인 경우

또는

bottom 매개 변수 값이 0 미만인 경우

예제

이 예제에서는 System.Drawing, System.Drawing.PrintingSystem.IO 네임스페이스를 사용합니다.

다음 코드 예제에서는 문서의 기본 페이지 설정을 각 면의 너비가 1인치인 여백으로 설정합니다.

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;
         
         // Create a new instance of Margins with one inch margins.
         Margins^ margins = gcnew Margins( 100,100,100,100 );
         pd->DefaultPageSettings->Margins = margins;
         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;
      // Create a new instance of Margins with one inch margins.
      Margins margins = new Margins(100,100,100,100);
      pd.DefaultPageSettings.Margins = margins;
      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
            ' Create a new instance of Margins with one 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("An error occurred printing the file - " & ex.Message)
    End Try
End Sub

적용 대상