DataFormats.StringFormat 字段

定义

指定 Windows 窗体字符串类格式,Windows 窗体使用此格式存储字符串对象。 此 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 窗体,在 Windows 窗体 之外创建的应用程序不会识别。

适用于

另请参阅