Clipboard.SetFileDropList(StringCollection) 方法

定義

清除剪貼簿,然後加入 FileDrop 格式的檔案名稱集合。

public:
 static void SetFileDropList(System::Collections::Specialized::StringCollection ^ filePaths);
public static void SetFileDropList (System.Collections.Specialized.StringCollection filePaths);
static member SetFileDropList : System.Collections.Specialized.StringCollection -> unit
Public Shared Sub SetFileDropList (filePaths As StringCollection)

參數

filePaths
StringCollection

StringCollection,其中包含檔案名稱。

例外狀況

無法清除剪貼簿。 這通常在剪貼簿由另一個處理序使用時發生。

目前執行緒 (Thread) 不是在單一執行緒 Apartment (STA) 模式。 將 STAThreadAttribute 加入至應用程式的 Main 方法。

filePathsnull

filePaths 不包含任何字串。

-或-

filePaths 內至少其中一個字串為 Empty,僅包含空格、包含一個或多個由 InvalidPathChars 定義的無效字元、為 null、包含冒號 (:),或是超過系統定義的最大長度。

如需詳細資訊,請參閱 InnerExceptionArgumentException 屬性。

範例

下列範例示範此成員。

// Demonstrates SetFileDropList, ContainsFileDroList, and GetFileDropList
public System.Collections.Specialized.StringCollection
    SwapClipboardFileDropList(
    System.Collections.Specialized.StringCollection replacementList)
{
    System.Collections.Specialized.StringCollection returnList = null;
    if (Clipboard.ContainsFileDropList())
    {
        returnList = Clipboard.GetFileDropList();
        Clipboard.SetFileDropList(replacementList);
    }
    return returnList;
}
' Demonstrates SetFileDropList, ContainsFileDroList, and GetFileDropList
Public Function SwapClipboardFileDropList(ByVal replacementList _
    As System.Collections.Specialized.StringCollection) _
    As System.Collections.Specialized.StringCollection

    Dim returnList As System.Collections.Specialized.StringCollection _
        = Nothing

    If Clipboard.ContainsFileDropList() Then

        returnList = Clipboard.GetFileDropList()
        Clipboard.SetFileDropList(replacementList)
    End If

    Return returnList

End Function

備註

檔案卸載清單是包含檔案路徑資訊的字串集合。

檔案卸載清單會儲存在剪貼簿上做為 String 陣列。 這個方法會在 filePathsString 將陣列新增至剪貼簿之前,先轉換成陣列。

若要從剪貼簿擷取檔案卸載清單,請先使用 ContainsFileDropList 方法來判斷剪貼簿是否包含該格式的資料,然後再使用 GetFileDropList 方法擷取資料。

注意

類別 Clipboard 只能在設定為單一線程 Apartment (STA) 模式的執行緒中使用。 若要使用這個類別,請確定您的 Main 方法已標示 STAThreadAttribute 為 屬性。

適用於

另請參閱