방법: DocumentList 컨트롤 사용

업데이트: 2007년 11월

주로 파일 작업을 수행하는 응용 프로그램의 경우 DocumentList 컨트롤을 사용하여 내 문서 폴더에서 파일 및 폴더 목록을 사용자 지정할 수 있습니다. 이 방법은 Microsoft Pocket Word 및 Microsoft Pocket Excel의 동작 방식과 비슷합니다. DocumentList 컨트롤을 사용하여 다음과 같은 기능을 수행할 수 있습니다.

  • 폴더와 파일을 선택, 삭제, 이동 및 복사하고 이름을 바꿀 수 있습니다.

  • 파일 이름, 날짜 또는 크기별로 정렬할 수 있습니다.

  • 파일을 전자 메일에 첨부하여 보낼 수 있습니다.

  • 적외선 통신을 사용하여 파일을 다른 장치로 보낼 수 있습니다.

DocumentList 컨트롤을 구현하려면

  1. DocumentList를 포함하는 Pocket PC Windows 응용 프로그램을 만듭니다.

  2. Filter 속성을 사용하여 액세스할 수 있는 파일 형식을 지정합니다.

  3. FilterIndex 속성을 사용하여 처음에 표시되는 파일을 지정합니다.

  4. SelectedDirectory 속성을 사용하여 기본 폴더를 지정합니다.

  5. DocumentActivated 이벤트를 처리하는 코드를 작성합니다.

  6. DeletingDocument 이벤트를 처리하는 코드를 작성합니다.

  7. SelectedDirectoryChanged 이벤트를 처리하는 코드를 작성합니다.

예제

이 예제에서는 DocumentList 컨트롤의 Parent 속성을 폼으로 설정하여 컨트롤이 폼의 전체 클라이언트 영역을 사용하도록 합니다. 더 작은 영역을 사용하게 하려면 이 컨트롤을 Panel 안에 배치하고 길이를 지정하면 됩니다. DocumentList의 너비는 폼의 너비여야 합니다.

 ' Set up file extension filters for a
 ' DocumentList and set the initial folder
 ' to the Busines folder under My Documents.
 Sub SetupDocList()

     ' Assumes an instance of DocumentList,
     ' documentList1, has been declared.
     With DocumentList1
         .Parent = Me
         .Filter = " |*.*| |*.txt;*.xml| |*.pwi;*.pdt| " & _
             "|*.pxl;*.psw| |*.jpg;*.gif;*.bmp| |*.wav;*.wmv;*.mpg;"
         .FilterIndex = 0
         .SelectedDirectory = "Business"
     End With

 End Sub

' Handle the DocumentedActivated
' event with code to open the file.
 Private Sub DocList_DocumentActivated(ByVal sender As Object, _
     ByVal docevent As Microsoft.WindowsCE.Forms.DocumentListEventArgs) _
     Handles DocumentList1.DocumentActivated

     StatusBar1.Text = "Activated: " & docevent.Path
 ' Add code to open the selected file.

 End Sub

 ' Handle the DeletingDocument 
 ' event with code to close the file.
 Private Sub DocList_DeletingDocument(ByVal sender As Object, _
     ByVal docevent As Microsoft.WindowsCE.Forms.DocumentListEventArgs) _
     Handles DocumentList1.DeletingDocument

     StatusBar1.Text = "Deleted: " & docevent.Path
     ' Add code to close any instances of the file.

 End Sub

 ' Handle the SelectedDirectoryChanged
 ' event with code that sets the correct
 ' path for opening and closing files.
 Private Sub DocList_SelectedDirectoryChanged( _
     ByVal sender As Object,  ByVal e As System.EventArgs) _
     Handles DocumentList1.SelectedDirectoryChanged

     StatusBar1.Text = "Folder: " & DocumentList1.SelectedDirectory
     ' Add code to access the selected folder to open and close files.    

 End Sub
// Set up file extension filters for a
// DocumentList and set the initial folder
// to the Busines folder under My Documents.
 private void SetupDocList()
 {

     // Assumes an instance of DocumentList,
     // documentList1, has been declared.
     documentList1.Parent = this;

     // Create event handlers for DocumentList events.
     documentList1.DocumentActivated +=
         new DocumentListEventHandler(this.OnDocActivated);

     documentList1.SelectedDirectoryChanged +=
         new EventHandler(this.OnFolderSel);

     documentList1.DeletingDocument +=
         new DocumentListEventHandler(this.OnDelDoc);

     documentList1.Filter = " |*.*| |*.txt;*.xml| |*.pwi;*.pdt| " +
         "|*.pxl;*.psw| |*.jpg;*.gif;*.bmp| |*.wav;*.wmv;*.mpg;";
     documentList1.FilterIndex = 0;
     documentList1.SelectedDirectory = "Business";
 }

 private void OnDelDoc(object obj, DocumentListEventArgs DocArgs)
 {
     statusBar1.Text += "Deleted: " + DocArgs.Path;

     // Add code to close any instances of the file.
 }

 private void OnDocActivated(object obj, DocumentListEventArgs DocArgs)
 {
     statusBar1.Text = "Activated: " + DocArgs.Path;

     // Add code to open the selected file.
 }
 private void OnFolderSel(object obj, EventArgs eventg)
 {
     statusBar1.Text = "Folder: " + documentList1.SelectedDirectory;

     // Add code to access the selected folder to open and close files.
 }

코드 컴파일

이 예제에는 다음과 같은 네임스페이스에 대한 참조가 필요합니다.

참고 항목

참조

DocumentList

기타 리소스

Pocket PC 개발 및 .NET Compact Framework