添加链接
link之家
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
相关文章推荐
豪气的创口贴  ·  having bad problem ...·  1 年前    · 
会开车的罐头  ·  CSS ...·  1 年前    · 
public:
 System::Object ^ GetData(System::String ^ format);
public object GetData (string format);
public object? GetData (string format);
abstract member GetData : string -> obj
Public Function GetData (format As String) As Object

此示例使用 DataObject 类,该类实现 IDataObject, 以演示 方法的 GetData 用法。 方法用于检索存储在 中的数据 myDataObject ,该数据与 Text 格式相关联。 该示例假定你已创建了一个名为 Form Form1 和一个名为 TextBox textBox1

private: void GetData1() // Creates a new data object using a string and the text format. String^ myString = "My text string"; DataObject^ myDataObject = gcnew DataObject( DataFormats::Text,myString ); // Displays the string in a text box. textBox1->Text = myDataObject->GetData( DataFormats::Text )->ToString(); private void GetData1() // Creates a new data object using a string and the text format. string myString = "My text string"; DataObject myDataObject = new DataObject(DataFormats.Text, myString); // Displays the string in a text box. textBox1.Text = myDataObject.GetData(DataFormats.Text).ToString(); Private Sub GetData1() ' Creates a new data object using a string and the text format. Dim myString As String = "My text string" Dim myDataObject As New DataObject(DataFormats.Text, myString) ' Displays the string in a text box. textBox1.Text = myDataObject.GetData(DataFormats.Text).ToString() End Sub

如果此方法找不到指定格式的数据,它会尝试将数据转换为格式。 如果无法将数据转换为指定的格式,此方法将 null 返回 。

若要确定数据是否与 数据关联或可转换为 格式,请在调用 之前调用 GetDataPresent GetData 。 调用 GetFormats 此实例中存储的数据的有效格式列表。

如果存储的数据指定允许转换,并且请求的格式与存储的格式兼容,则可以将数据转换为另一种格式。 例如,存储为 Unicode 的数据可以转换为文本。

有关此方法的实现,请参阅 DataObject.GetData

System::Object ^ GetData(Type ^ format);
public object GetData (Type format);
public object? GetData (Type format);
abstract member GetData : Type -> obj
Public Function GetData (format As Type) As Object

此示例使用 DataObject 实现 的 IDataObject 类来演示 方法的 GetData 用法。 方法用于检索中 myObject 存储的数据,该数据与特定类型 myType 相关联。 检索到的数据的类型显示在消息框中。 该示例假定你已创建了一个名为 Form Form1

private: void GetData2() // Creates a component. Component^ myComponent = gcnew Component; // Creates a data object, and assigns it the component. DataObject^ myDataObject = gcnew DataObject( myComponent ); // Creates a type, myType, to store the type of data. Type^ myType = myComponent->GetType(); // Retrieves the data using myType to represent its type. Object^ myObject = myDataObject->GetData( myType ); if ( myObject != nullptr ) MessageBox::Show( "The data type stored in the data object is " + myObject->GetType()->Name + "." ); MessageBox::Show( "Data of the specified type was not stored in the data object." ); private void GetData2() // Creates a component. Component myComponent = new Component(); // Creates a data object, and assigns it the component. DataObject myDataObject = new DataObject(myComponent); // Creates a type, myType, to store the type of data. Type myType = myComponent.GetType(); // Retrieves the data using myType to represent its type. Object myObject = myDataObject.GetData(myType); if(myObject != null) MessageBox.Show("The data type stored in the data object is " + myObject.GetType().Name + "."); MessageBox.Show("Data of the specified type was not stored " + "in the data object."); Private Sub GetData2() ' Creates a component. Dim myComponent As New System.ComponentModel.Component() ' Creates a data object, and assigns it the component. Dim myDataObject As New DataObject(myComponent) ' Creates a type, myType, to store the type of data. Dim myType As Type = myComponent.GetType() ' Retrieves the data using myType to represent its type. Dim myObject As [Object] = myDataObject.GetData(myType) If (myObject IsNot Nothing) Then MessageBox.Show("The data type stored in the data object is " + myObject.GetType().Name + ".") MessageBox.Show("Data of the specified type was not stored " + "in the data object.") End If End Sub

如果此方法找不到指定格式的数据,它会尝试将数据转换为格式。 如果无法将数据转换为指定的格式,此方法将 null 返回 。

若要确定数据是否与 数据关联或可转换为 格式,请在调用 之前调用 GetDataPresent GetData 。 调用 GetFormats 此实例中存储的数据的有效格式列表。

如果存储的数据指定允许转换,并且请求的格式与存储的格式兼容,则可以将数据转换为另一种格式。 例如,存储为 Unicode 的数据可以转换为文本。

有关此方法的实现,请参阅 DataObject.GetData

public:
 System::Object ^ GetData(System::String ^ format, bool autoConvert);
public object GetData (string format, bool autoConvert);
public object? GetData (string format, bool autoConvert);
abstract member GetData : string * bool -> obj
Public Function GetData (format As String, autoConvert As Boolean) As Object

此示例使用 DataObject 实现 的 IDataObject 类来演示 方法的 GetData 用法。 该示例使用 autoConvert 参数来指定是否转换数据格式,检索存储在 DataObject 中的数据。 首先, myDataObject 使用文本数据创建 。 然后,该示例尝试两次检索数据。 在第一次试用中,它将格式指定为字符串, autoConvert 并将 参数设置为 false 。 此试用版失败,结果显示在标有“消息 #1”的消息框中。第二次试用中,该示例检索参数设置为 true autoConvert 相同数据。 此试用成功,结果显示在标有“消息 #2”的消息框中。该示例假定你已创建一个名为 Form Form1

private: void GetData3() // Creates a new data object using a text string. String^ myString = "Hello World!"; DataObject^ myDataObject = gcnew DataObject( DataFormats::Text,myString ); // Displays the string with autoConvert equal to false. if ( myDataObject->GetData( "System::String", false ) != nullptr ) // Displays the string in a message box. MessageBox::Show( myDataObject->GetData( "System::String", false ) + ".", "Message #1" ); MessageBox::Show( "Could not find data of the specified format.", "Message #1" ); // Displays a not found message in a message box. // Displays the string in a text box with autoConvert equal to true. String^ myData = "The data is " + myDataObject->GetData( "System::String", true ) + "."; MessageBox::Show( myData, "Message #2" ); private void GetData3() // Creates a new data object using a text string. string myString = "Hello World!"; DataObject myDataObject = new DataObject(DataFormats.Text, myString); // Displays the string with autoConvert equal to false. if (myDataObject.GetData("System.String", false) != null) // Displays the string in a message box. MessageBox.Show(myDataObject.GetData("System.String", false).ToString() + ".", "Message #1"); // Displays a not found message in a message box. MessageBox.Show("Could not find data of the specified format.", "Message #1"); // Displays the string in a text box with autoConvert equal to true. string myData = "The data is " + myDataObject.GetData("System.String", true).ToString() +"."; MessageBox.Show(myData,"Message #2"); Private Sub GetData3() ' Creates a new data object using a text string. Dim myString As String = "Hello World!" Dim myDataObject As New DataObject(DataFormats.Text, myString) ' Displays the string with autoConvert equal to false. If (myDataObject.GetData("System.String", False) IsNot Nothing) Then ' Displays the string in a message box. MessageBox.Show(myDataObject.GetData("System.String", False).ToString() + ".", "Message #1") ' Displays a not found message in a message box. MessageBox.Show("Could not find data of the specified format.", "Message #1") End If ' Displays the string in a text box with autoConvert equal to true. Dim myData As String = "The data is " + myDataObject.GetData("System.String", True).ToString() MessageBox.Show(myData, "Message #2") End Sub

autoConvert 如果 参数为 true ,并且此方法找不到指定格式的数据,则会尝试将数据转换为格式。 如果数据无法转换为指定格式,或者数据存储 autoConvert 时参数设置为 false ,则此方法返回 null

autoConvert 如果 参数为 false ,则此方法返回指定格式的数据,或者 null 找不到此格式的数据。

若要确定数据是否与 数据关联或可转换为 格式,请在调用 之前调用 GetDataPresent GetData 。 调用 GetFormats 此实例中存储的数据的有效格式列表。

如果存储的数据指定允许转换,并且请求的格式与存储的格式兼容,则可以将数据转换为另一种格式。 例如,存储为 Unicode 的数据可以转换为文本。

有关此方法的实现,请参阅 DataObject.GetData