다음을 통해 공유


선택한 용지 공급 검색

Web Form 또는 Windows Form에 추가한 paperSourceList 컨트롤에는 현재 선택된 프린터에 따라 사용자 지정 용지 공급 목록이 표시됩니다. 런타임에 최종 사용자가 paperSourceList 컨트롤에서 용지 공급을 선택하면 선택된 이 용지 공급이 보고서의 CustomPaperSource 속성에 적용되어야 합니다.

그러나 paperSourceList 컨트롤에서는 다음 두 형식의 값만 검색할 수 있습니다.

  • 선택된 항목의 문자열 값
  • 선택된 항목의 정수 인덱스

문자열 또는 정수 중 어떤 형식도 CustomPaperSource 속성과 호환되지 않으며, 여기에는 System.Drawing.Printing.PaperSource 형식만 할당할 수 있습니다.

따라서 이 부분에서는 paperSourceList 컨트롤의 선택된 인덱스에 따라 올바른 PaperSource 인스턴스를 결정한 다음 반환하는 GetSelectedPaperSource() 도우미 메서드를 만듭니다.

이렇게 하려면 메서드에서 현재 선택된 프린터의 PaperSources 컬렉션 전체를 반복한 다음 PaperSource 인스턴스의 SourceName 문자열 속성을 선택된 항목의 문자열 값과 비교해야 합니다. 일치하는 PaperSource가 발견되면 메서드에서 해당 PaperSource 인스턴스를 반환합니다.

GetSelectedPaperSource() 메서드를 만들려면

  1. PaperSource 인스턴스를 반환하는 GetSelectedPaperSource() 도우미 메서드를 클래스 맨 아래에 만듭니다.
``` vb
Private Function GetSelectedPaperSource() As System.Drawing.Printing.PaperSource
End Function
```

``` csharp
private System.Drawing.Printing.PaperSource GetSelectedPaperSource()
{
}
```

이 단계의 나머지 코드는 GetSelectedPaperSource() 메서드에 포함됩니다.
  1. 이 메서드 내에서 System.Drawing.Printing 네임스페이스의 PaperSource 클래스를 선언하고 인스턴스화합니다.

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

    Dim myPrinterSettings As System.Drawing.Printing.PrinterSettings = New System.Drawing.Printing.PrinterSettings()
    
    System.Drawing.Printing.PrinterSettings printerSettings = new System.Drawing.Printing.PrinterSettings();
    
  3. PrinterSettings 인스턴스의 PrinterName 속성에 CURRENT_PRINTER 문자열 상수를 할당합니다.

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

    For Each myPaperSource As System.Drawing.Printing.PaperSource In myPrinterSettings.PaperSources
    Next
    
    foreach (System.Drawing.Printing.PaperSource paperSource in printerSettings.PaperSources)
    {
    }
    
  5. foreach 루프 내에서 PaperSource 인스턴스의 SourceName 속성이 paperSourceList 컨트롤에서 선택한 항목과 일치하는지 여부를 테스트하는 조건 블록을 추가합니다.

<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>선택한 항목의 이름은 Windows 프로젝트의 ComboBox 컨트롤과 웹 사이트의 DropDownList 컨트롤에서 서로 다릅니다. 아래 나열된 적절한 지침을 따르십시오.</p></td>
</tr>
</tbody>
</table>

1.  Windows 프로젝트의 경우 paperSourceList 컨트롤에서 선택한 항목의 이름을 SelectedText 속성으로 지정하는 조건 블록을 만듭니다.
    
    ``` vb
    If myPaperSource.SourceName = paperSourceList.SelectedText Then
    End If
    ```
    
    ``` csharp
    if (paperSource.SourceName == paperSourceList.SelectedText)
    {
    }
    ```

2.  웹 사이트의 경우 paperSourceList 컨트롤에서 선택한 항목의 이름을 SelectedItem.Text 속성으로 지정하는 조건 블록을 만듭니다.
    
    ``` vb
    If myPaperSource.SourceName = paperSourceList.SelectedItem.Text Then
    End If
    ```
    
    ``` csharp
    if (paperSource.SourceName == paperSourceList.SelectedItem.Text)
    {
    }
    ```
  1. 조건 블록 내에서 현재 foreach 루프 반복의 PaperSource 인스턴스를 메서드의 맨 위에 선언된 selectedPaperSource 인스턴스에 할당합니다.

    selectedPaperSource = myPaperSource
    
    selectedPaperSource = paperSource;
    
  2. 조건 블록 및 foreach 루프 외부의 메서드에서 selectedPaperSource 인스턴스를 반환합니다.

    Return selectedPaperSource
    
    return selectedPaperSource;