Clipboard.GetAudioStream 方法

定義

從剪貼簿擷取音效串流。Retrieves an audio stream from the Clipboard.

public:
 static System::IO::Stream ^ GetAudioStream();
public static System.IO.Stream GetAudioStream ();
static member GetAudioStream : unit -> System.IO.Stream
Public Shared Function GetAudioStream () As Stream

傳回

Stream

如果剪貼簿不包含任何 Stream 格式的資料,則為包含音訊資料或 nullWaveAudioA Stream containing audio data or null if the Clipboard does not contain any data in the WaveAudio format.

例外狀況

無法清除剪貼簿。The Clipboard could not be cleared. 這通常在剪貼簿由另一個處理序使用時發生。This typically occurs when the Clipboard is being used by another process.

目前執行緒 (Thread) 不是在單一執行緒 Apartment (STA) 模式。The current thread is not in single-threaded apartment (STA) mode. STAThreadAttribute 加入至應用程式的 Main 方法。Add the STAThreadAttribute to your application's Main method.

範例

下列範例示範這個成員。The following example demonstrates this member.

// Demonstrates SetAudio, ContainsAudio, and GetAudioStream.
public System.IO.Stream SwapClipboardAudio(
    System.IO.Stream replacementAudioStream)
{
    System.IO.Stream returnAudioStream = null;
    if (Clipboard.ContainsAudio())
    {
        returnAudioStream = Clipboard.GetAudioStream();
        Clipboard.SetAudio(replacementAudioStream);
    }
    return returnAudioStream;
}
' Demonstrates SetAudio, ContainsAudio, and GetAudioStream.
Public Function SwapClipboardAudio( _
    ByVal replacementAudioStream As System.IO.Stream) _
    As System.IO.Stream

    Dim returnAudioStream As System.IO.Stream = Nothing

    If (Clipboard.ContainsAudio()) Then
        returnAudioStream = Clipboard.GetAudioStream()
        Clipboard.SetAudio(replacementAudioStream)
    End If

    Return returnAudioStream

End Function

備註

ContainsAudio 可以使用方法來判斷剪貼簿是否包含音訊資料,然後再使用這個方法進行抓取。Use the ContainsAudio method to determine whether the Clipboard contains audio data before retrieving it with this method.

使用 SetAudio 方法將音訊資料新增至剪貼簿。Use the SetAudio method to add audio data to the Clipboard.

注意

Clipboard類別只能用在設定為單一線程單元 (STA) 模式的執行緒中。The Clipboard class can only be used in threads set to single thread apartment (STA) mode. 若要使用這個類別,請確定您的 Main 方法是以 STAThreadAttribute 屬性標記。To use this class, ensure that your Main method is marked with the STAThreadAttribute attribute.

適用於

另請參閱