Clipboard.GetDataObject Yöntem
Tanım
Önemli
Bazı bilgiler ürünün ön sürümüyle ilgilidir ve sürüm öncesinde önemli değişiklikler yapılmış olabilir. Burada verilen bilgilerle ilgili olarak Microsoft açık veya zımni hiçbir garanti vermez.
Sistem Panosu'nda bulunan verileri alır.
public:
static System::Windows::Forms::IDataObject ^ GetDataObject();
public static System.Windows.Forms.IDataObject GetDataObject();
public static System.Windows.Forms.IDataObject? GetDataObject();
static member GetDataObject : unit -> System.Windows.Forms.IDataObject
Public Shared Function GetDataObject () As IDataObject
Döndürülenler
IDataObject Pano'da bulunan verileri temsil eden veya Pano'da null veri olmayan bir.
Özel durumlar
Veriler Pano'dan alınamadı. Bu durum genellikle Pano başka bir işlem tarafından kullanıldığında oluşur.
Geçerli iş parçacığı tek iş parçacıklı daire (STA) modunda değil ve MessageLoop özellik değeri şeklindedir true.
STAThreadAttribute öğesini uygulamanızın yöntemine Main ekleyin.
Örnekler
Aşağıdaki kod örneği, verileri sistem Panosu'na yerleştirmek ve sistem Panosu'ndan almak için yöntemleri kullanır Clipboard . Bu kod, , button1, button2ve textBox1 değerlerinin forma yerleştirildiğini varsayartextBox2.
yöntemi, button1_Click seçili metni metin kutusundan alıp sistem Panosu'na yerleştirmeyi çağırır SetDataObject .
yöntemi, button2_Click sistem Panosu'ndan veri almak için öğesini çağırır GetDataObject . Kod, döndürülen verileri ayıklamak için ve IDataObject kullanırDataFormats. Veriler içinde textBox2görüntülenir.
private:
void button1_Click( Object^ /*sender*/, System::EventArgs^ /*e*/ )
{
// Takes the selected text from a text box and puts it on the clipboard.
if ( !textBox1->SelectedText->Equals( "" ) )
{
Clipboard::SetDataObject( textBox1->SelectedText );
}
else
{
textBox2->Text = "No text selected in textBox1";
}
}
void button2_Click( Object^ /*sender*/, System::EventArgs^ /*e*/ )
{
// Declares an IDataObject to hold the data returned from the clipboard.
// Retrieves the data from the clipboard.
IDataObject^ iData = Clipboard::GetDataObject();
// Determines whether the data is in a format you can use.
if ( iData->GetDataPresent( DataFormats::Text ) )
{
// Yes it is, so display it in a text box.
textBox2->Text = (String^)(iData->GetData( DataFormats::Text ));
}
else
{
// No it is not.
textBox2->Text = "Could not retrieve data off the clipboard.";
}
}
private void button1_Click(object sender, System.EventArgs e) {
// Takes the selected text from a text box and puts it on the clipboard.
if(textBox1.SelectedText != "")
Clipboard.SetDataObject(textBox1.SelectedText);
else
textBox2.Text = "No text selected in textBox1";
}
private void button2_Click(object sender, System.EventArgs e) {
// Declares an IDataObject to hold the data returned from the clipboard.
// Retrieves the data from the clipboard.
IDataObject iData = Clipboard.GetDataObject();
// Determines whether the data is in a format you can use.
if(iData.GetDataPresent(DataFormats.Text)) {
// Yes it is, so display it in a text box.
textBox2.Text = (String)iData.GetData(DataFormats.Text);
}
else {
// No it is not.
textBox2.Text = "Could not retrieve data off the clipboard.";
}
}
Private Sub button1_Click(sender As Object, e As System.EventArgs)
' Takes the selected text from a text box and puts it on the clipboard.
If textBox1.SelectedText <> "" Then
Clipboard.SetDataObject(textBox1.SelectedText)
Else
textBox2.Text = "No text selected in textBox1"
End If
End Sub
Private Sub button2_Click(sender As Object, e As System.EventArgs)
' Declares an IDataObject to hold the data returned from the clipboard.
' Retrieves the data from the clipboard.
Dim iData As IDataObject = Clipboard.GetDataObject()
' Determines whether the data is in a format you can use.
If iData.GetDataPresent(DataFormats.Text) Then
' Yes it is, so display it in a text box.
textBox2.Text = CType(iData.GetData(DataFormats.Text), String)
Else
' No it is not.
textBox2.Text = "Could not retrieve data off the clipboard."
End If
End Sub
Açıklamalar
Pano'dan döndürülen nesnenin veri türü farklılık gösterebileceğinden, bu yöntem içindeki IDataObjectverileri döndürür. Ardından, uygun veri türündeki IDataObject verileri ayıklamak için arabiriminin yöntemlerini kullanabilirsiniz.
Bu yöntem, verileri 100 milisaniyelik aralıklarla on kez almaya çalışır ve tüm girişimlerin başarısız olması durumunda bir ExternalException oluşturur.
Note
Clipboard sınıfı yalnızca tek iş parçacığı dairesi (STA) moduna ayarlanmış iş parçacıklarında kullanılabilir. Bu sınıfı kullanmak için Main yönteminizin STAThreadAttribute özniteliğiyle işaretlendiğinden emin olun.