다음을 통해 공유


인쇄 옵션 컨트롤 채우기

이 부분에서는 Web Form 또는 Windows Form에서 DropDownList(또는 ComboBox) 컨트롤을 채웁니다. 컨트롤을 채우려면 코드 숨김 클래스에 코드를 작성해야 합니다.

대부분의 컨트롤은 CrystalDecisions.Shared 네임스페이스의 프린터 열거형 값으로 쉽게 채울 수 있습니다. 그러나 이러한 컨트롤 중 paperSourceList는 현재 선택된 프린터를 기반으로 하는 사용자 지정 용지 공급을 통해 채워야 합니다. 따라서 첫 번째 단계는 현재 프린터를 지정한 다음 이 프린터에서 사용자 지정 용지 공급의 ArrayList를 생성하는 도우미 메서드를 만드는 것입니다.

"선택한 용지 공급 검색" 작업으로 이동합니다.

GetPaperSources() 도우미 메서드를 만들려면

  1. Web Form을 엽니다.

  2. 보기 메뉴에서 코드를 클릭합니다.

  3. 클래스 위쪽에 프린터의 네트워크 경로에 대한 문자열 상수를 만듭니다.

<table>
<colgroup>
<col style="width: 100%" />
</colgroup>
<thead>
<tr class="header">
<th><img src="images\e2c9s1d7.alert_note(ko-kr,VS.90).gif" alt="Note" class="note" />참고</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td><p>이 예제에서는 &quot;\\NetworkPrintServer2\\Printer15&quot;가 프린터 경로로 사용됩니다.</p></td>
</tr>
</tbody>
</table>

``` vb
Private Const CURRENT_PRINTER As String = "\\NetworkPrintServer2\Printer15"
```

``` csharp
private const string CURRENT_PRINTER = @"\\NetworPrinterServer2\Printer15";
```
  1. 클래스 위에 System.Collections 네임스페이스에 대한 "Imports"[Visual Basic] 또는 "using"[C#] 문을 추가합니다.
``` vb
Imports System.Collections
```

``` csharp
using System.Collections;
```
  1. ArrayList를 반환하는 GetPaperSources() 도우미 메서드를 클래스 맨 아래에 만듭니다.
``` vb
Private Function GetPaperSources() As ArrayList
End Function
```

``` csharp
private ArrayList GetPaperSources()
{
}
```

이 단계의 나머지 코드는 GetPaperSources() 메서드에 포함됩니다.
  1. 이 메서드 내에서 ArrayList를 선언하고 인스턴스화합니다.

    Dim myArrayList As ArrayList = New ArrayList()
    
    ArrayList arrayList = new ArrayList();
    
  2. System.Drawing.Printing 네임스페이스에서 PrinterSettings 클래스를 선언하고 인스턴스화합니다.

<table>
<colgroup>
<col style="width: 100%" />
</colgroup>
<thead>
<tr class="header">
<th><img src="images\e2c9s1d7.alert_note(ko-kr,VS.90).gif" alt="Note" class="note" />참고</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td><p>이 자습서에 사용된 몇몇 클래스의 이름은 System.Drawing.Printing 네임스페이스와 CrystalDecisions.Shared 네임스페이스에서 되풀이됩니다. 이름이 되풀이되는 클래스가 자습서에 사용되는 경우 이 클래스가 속한 네임스페이스를 명확히 하기 위해 클래스 이름 앞에 전체 네임스페이스가 붙습니다.</p></td>
</tr>
</tbody>
</table>

``` vb
Dim myPrinterSettings As System.Drawing.Printing.PrinterSettings = New System.Drawing.Printing.PrinterSettings()
```

``` csharp
System.Drawing.Printing.PrinterSettings printerSettings = new System.Drawing.Printing.PrinterSettings();
```
  1. PrinterSettings 인스턴스의 PrinterName 속성을 CURRENT_PRINTER 문자열 상수로 설정합니다.

    myPrinterSettings.PrinterName = CURRENT_PRINTER
    
    printerSettings.PrinterName = CURRENT_PRINTER;
    
  2. 인덱싱된 PaperSources 클래스 인스턴스의 각 PaperSource 인스턴스를 반복하는 foreach 루프를 만듭니다.

    Dim myPaperSource As System.Drawing.Printing.PaperSource
    For Each myPaperSource As System.Drawing.Printing.PaperSource In myPrinterSettings.PaperSources
    Next
    
    foreach (System.Drawing.Printing.PaperSource paperSource in
    printerSettings.PaperSources)
    {
    }
    
  3. foreach 루프 내에서 PaperSource 인스턴스의 SourceName 속성을 ArrayList에 추가합니다.

    myArrayList.Add(myPaperSource.SourceName.ToString())
    
    arrayList.Add(paperSource.SourceName.ToString());
    
  4. foreach 루프 외부에 있는 메서드에서 ArrayList를 반환합니다.

    Return myArrayList
    
    return arrayList;
    
  5. 파일 메뉴에서 모두 저장을 클릭합니다.

이제 CrystalDecisions.Shared 네임스페이스의 열거형으로 처음 세 개의 DropDownList 컨트롤을 채워야 합니다. 네 번째 DropDownList 컨트롤은 방금 만든 GetPaperSources() 메서드를 통해 채웁니다.

  1. Web Form 또는 Windows Form을 엽니다.

  2. 보기 메뉴에서 디자이너를 클릭합니다.

  3. 폼에서 빈 영역을 두 번 클릭합니다.

페이지가 코드 뷰로 전환되고 Page\_Load() 이벤트 메서드(Web Form의 경우) 또는 Form1\_Load() 이벤트 메서드(Windows Form의 경우)가 생성됩니다.
  1. 웹 사이트를 개발하는 경우 Page_Load() 이벤트 메서드 내에 Not IsPostBack 조건 블록을 만듭니다.

    If Not IsPostBack Then
    End If
    
    if (!IsPostBack)
    {
    }
    
    Note참고

    Not IsPostBack 조건 블록은 페이지를 처음 로드할 때만 실행되는 코드를 캡슐화합니다. 컨트롤은 일반적으로 Not IsPostBack 조건 블록 내에서 데이터 값에 바인딩되므로 데이터 값과 그 이후의 컨트롤 이벤트는 페이지를 다시 로드할 때 재설정되지 않습니다.

  2. 다음 코드 줄은 Windows 프로젝트와 웹 사이트에서 다르게 배치됩니다.

    • Windows 프로젝트의 경우 다음 코드 줄이 Form_Load 이벤트 처리기에 배치되어야 합니다.
    • 웹 사이트의 경우 다음 코드 줄이 Page_Load 이벤트 처리기의 Not IsPostBack 조건 블록 내부에 중첩되어야 합니다.
    1. paperOrientationList 컨트롤 인스턴스의 DataSource 속성을 PaperOrientation 열거형의 값으로 설정합니다.

      paperOrientationList.DataSource = System.Enum.GetValues(GetType(PaperOrientation))
      
      paperOrientationList.DataSource = System.Enum.GetValues(typeof(PaperOrientation));
      
    2. paperSizeList 컨트롤 인스턴스의 DataSource 속성을 PaperSize 열거형의 값으로 설정합니다.

      paperSizeList.DataSource = System.Enum.GetValues(GetType(PaperSize))
      
      paperSizeList.DataSource = System.Enum.GetValues(typeof(PaperSize));
      
    3. printerDuplexList 컨트롤 인스턴스의 DataSource 속성을 PrinterDuplex 열거형의 값으로 설정합니다.

      printerDuplexList.DataSource = System.Enum.GetValues(GetType(PrinterDuplex))
      
      printerDuplexList.DataSource = System.Enum.GetValues(typeof(PrinterDuplex));
      
    4. paperSourceList 컨트롤 인스턴스의 DataSource 속성을 이전 부분에서 만든 GetPaperSources() 도우미 메서드로 설정합니다.

      paperSourceList.DataSource = GetPaperSources()
      
      paperSourceList.DataSource = GetPaperSources();
      
    5. 끝으로 웹 사이트를 빌드하는 경우 DataBind() 메서드에 대한 호출을 입력하여 네 개의 DropDownList 컨트롤의 값을 바인딩합니다.

      DataBind()
      
      DataBind();