共用方式為


DataFormats.StringFormat 欄位

定義

指定 Windows Form 字串類別格式,Windows Form 會用這個格式儲存字串物件。 這個 static 欄位是唯讀的。

public: static initonly System::String ^ StringFormat;
public static readonly string StringFormat;
 staticval mutable StringFormat : string
Public Shared ReadOnly StringFormat As String 

欄位值

範例

下列程式碼範例示範如何使用這個成員。

try
{
   String^ myString = "This is a String from the ClipBoard";
   // Sets the data to the Clipboard.   
   Clipboard::SetDataObject( myString );
   IDataObject^ myDataObject = Clipboard::GetDataObject();
   
   // Checks whether the data is present or not in the Clipboard.
   if ( myDataObject->GetDataPresent( DataFormats::StringFormat ) )
   {
      String^ clipString = (String^)(myDataObject->GetData( DataFormats::StringFormat ));
      Console::WriteLine( clipString );
   }
   else
   {
      Console::WriteLine( "No String information was contained in the clipboard." );
   }
}
catch ( Exception^ e ) 
{
   Console::WriteLine( e->Message );
}
try
{
    String myString = "This is a String from the ClipBoard";
    // Sets the data to the Clipboard.   
    Clipboard.SetDataObject(myString);
    IDataObject myDataObject = Clipboard.GetDataObject();

    // Checks whether the data is present or not in the Clipboard.
    if(myDataObject.GetDataPresent(DataFormats.StringFormat)) 
    {
        String clipString = (String)myDataObject.GetData(DataFormats.StringFormat);
        Console.WriteLine(clipString);
    } 
    else 
    {
        Console.WriteLine("No String information was contained in the clipboard.");
    }
}
catch(Exception e)
{
    Console.WriteLine(e.Message);
}
        Try
            Dim myString As String = "This is a String from the ClipBoard"
            ' Sets the data to the Clipboard.   
            Clipboard.SetDataObject(myString)
            Dim myDataObject As IDataObject = Clipboard.GetDataObject()
          
            ' Checks whether the data is present or not in the Clipboard.
            If myDataObject.GetDataPresent(DataFormats.StringFormat) Then
                Dim clipString As String = CType(myDataObject.GetData(DataFormats.StringFormat), String)
                Console.WriteLine(clipString)
            Else
                Console.WriteLine("No String information was contained in the clipboard.")
            End If
        Catch e As Exception
            Console.WriteLine(e.Message)
        End Try
   End Sub
End Class

備註

介面和 DataObject 類別會使用此 IDataObject 欄位來指定資料類型。

將 加入 IDataObject 至 或 的實作 DataObject 時,請使用此欄位做為 和 DataObject.SetData 方法的格式 IDataObject.SetData

若要查看此類型的物件是否存在,請使用此欄位做為 和 DataObject.GetDataPresent 方法的格式 IDataObject.GetDataPresent

若要取得此類型的物件,請使用這個 做為 和 DataObject.GetData 方法的格式 IDataObject.GetData

注意

字串類別格式僅適用于Windows Forms,而且無法由Windows Forms外部建立的應用程式辨識。

適用於

另請參閱