كيفية القيام بما يلي: استرداد بيانات في تنسيق بيانات معين

تبين الأمثلة التالية كيفية استرداد بيانات من بيانات الكائن في تنسيق محدد.

المثال

الوصف

التعليمة البرمجية الموجودة في المثال التالي يستخدم GetDataPresent(String) زيادة التحميل للاختيار الأول إذا المحدد يتوفر تنسيق (أصلاً أو عن طريق تحويل تلقائي); يسترد المثال في حالة توفر التنسيق المحدد باستخدام الأسلوبGetData(String) .

الرمز

Dim dataObject As New DataObject("Some string data to store...")

Dim desiredFormat As String = DataFormats.UnicodeText
Dim data() As Byte = Nothing

' Use the GetDataPresent method to check for the presence of a desired data format.
' This particular overload of GetDataPresent looks for both native and auto-convertible 
' data formats.
If dataObject.GetDataPresent(desiredFormat) Then
    ' If the desired data format is present, use one of the GetData methods to retrieve the
    ' data from the data object.
    data = TryCast(dataObject.GetData(desiredFormat), Byte())
End If
DataObject dataObject = new DataObject("Some string data to store...");

string desiredFormat = DataFormats.UnicodeText;
byte[] data = null;

// Use the GetDataPresent method to check for the presence of a desired data format.
// This particular overload of GetDataPresent looks for both native and auto-convertible 
// data formats.
if (dataObject.GetDataPresent(desiredFormat))
{
    // If the desired data format is present, use one of the GetData methods to retrieve the
    // data from the data object.
    data = dataObject.GetData(desiredFormat) as byte[];
}

المثال

الوصف

التعليمة البرمجية الموجودة في المثال التالي يستخدم GetDataPresent(String, Boolean) زيادة التحميل للاختيار الأول إذا المحدد يتوفر تنسيق (أصلاً أو عن طريق تحويل تلقائي); يسترد المثال في حالة توفر التنسيق المحدد باستخدام الأسلوبGetData(String) .

الرمز

Dim dataObject As New DataObject("Some string data to store...")

Dim desiredFormat As String = DataFormats.UnicodeText
Dim noAutoConvert As Boolean = False
Dim data() As Byte = Nothing

' Use the GetDataPresent method to check for the presence of a desired data format.
' The autoconvert parameter is set to false to filter out auto-convertible data formats,
' returning true only if the specified data format is available natively.
If dataObject.GetDataPresent(desiredFormat, noAutoConvert) Then
    ' If the desired data format is present, use one of the GetData methods to retrieve the
    ' data from the data object.
    data = TryCast(dataObject.GetData(desiredFormat), Byte())
End If
DataObject dataObject = new DataObject("Some string data to store...");

string desiredFormat = DataFormats.UnicodeText;
bool noAutoConvert = false;
byte[] data = null;

// Use the GetDataPresent method to check for the presence of a desired data format.
// The autoconvert parameter is set to false to filter out auto-convertible data formats,
// returning true only if the specified data format is available natively.
if (dataObject.GetDataPresent(desiredFormat, noAutoConvert))
{
    // If the desired data format is present, use one of the GetData methods to retrieve the
    // data from the data object.
    data = dataObject.GetData(desiredFormat) as byte[];
}

راجع أيضًا:

المرجع

IDataObject

المبادئ

نظرة عامة حول السحب و الإفلات