方法 : DocumentList コントロールを使用する

更新 : 2007 年 11 月

アプリケーションがファイル操作を中心としている場合、DocumentList コントロールを使用すると、マイ ドキュメント フォルダ内のフォルダおよびファイルのリストをカスタマイズして表示できます。これは、Microsoft Pocket Word および Microsoft Pocket Excel での操作方法に似ています。このコントロールには、次の機能が用意されています。

  • ファイルおよびフォルダの選択、削除、コピー、移動、および名前の変更。

  • ファイルの名前、日付、またはサイズによる並べ替え。

  • 電子メールの添付ファイルとしてファイル送信。

  • 赤外線通信による他のデバイスへのファイル送信。

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