RichTextBox.Paste(DataFormats+Format) Methode
Definition
Wichtig
Einige Informationen beziehen sich auf Vorabversionen, die vor dem Release ggf. grundlegend überarbeitet werden. Microsoft übernimmt hinsichtlich der hier bereitgestellten Informationen keine Gewährleistungen, seien sie ausdrücklich oder konkludent.
Fügt den Inhalt der Zwischenablage im angegebenen Zwischenablageformat ein.
public:
void Paste(System::Windows::Forms::DataFormats::Format ^ clipFormat);
public void Paste(System.Windows.Forms.DataFormats.Format clipFormat);
override this.Paste : System.Windows.Forms.DataFormats.Format -> unit
Public Sub Paste (clipFormat As DataFormats.Format)
Parameter
- clipFormat
- DataFormats.Format
Das Format der Zwischenablage, in dem die Daten aus der Zwischenablage abgerufen werden sollen.
Beispiele
Im folgenden Codebeispiel wird veranschaulicht, wie die Methode zum Einfügen einer Bitmap in das Paste Steuerelement verwendet RichTextBox wird. Nach dem Öffnen einer Bitmap aus datei verwendet das Beispiel die SetDataObject-Methode, um die Bitmap in die Windows Zwischenablage zu kopieren. Schließlich ruft das Beispiel das Format für das Bitmap Objekt ab, überprüft, ob das Format in das RichTextBox Steuerelement eingefügt werden kann, und verwendet die Paste Methode zum Einfügen der Daten.
private:
bool pasteMyBitmap( String^ fileName )
{
// Open an bitmap from file and copy it to the clipboard.
Bitmap^ myBitmap = gcnew Bitmap( fileName );
// Copy the bitmap to the clipboard.
Clipboard::SetDataObject( myBitmap );
// Get the format for the object type.
DataFormats::Format^ myFormat = DataFormats::GetFormat( DataFormats::Bitmap );
// After verifying that the data can be pasted, paste it.
if ( richTextBox1->CanPaste( myFormat ) )
{
richTextBox1->Paste( myFormat );
return true;
}
else
{
MessageBox::Show( "The data format that you attempted to paste is not supported by this control." );
return false;
}
}
private bool pasteMyBitmap(string fileName)
{
// Open an bitmap from file and copy it to the clipboard.
Bitmap myBitmap = new Bitmap(fileName);
// Copy the bitmap to the clipboard.
Clipboard.SetDataObject(myBitmap);
// Get the format for the object type.
DataFormats.Format myFormat = DataFormats.GetFormat(DataFormats.Bitmap);
// After verifying that the data can be pasted, paste it.
if(richTextBox1.CanPaste(myFormat))
{
richTextBox1.Paste(myFormat);
return true;
}
else
{
MessageBox.Show("The data format that you attempted to paste is not supported by this control.");
return false;
}
}
Private Function PasteMyBitmap(ByVal Filename As String) As Boolean
'Open an bitmap from file and copy it to the clipboard.
Dim MyBitmap As Bitmap
MyBitmap = Bitmap.FromFile(Filename)
' Copy the bitmap to the clipboard.
Clipboard.SetDataObject(MyBitmap)
' Get the format for the object type.
Dim MyFormat As DataFormats.Format = DataFormats.GetFormat(DataFormats.Bitmap)
' After verifying that the data can be pasted, paste it.
If RichTextBox1.CanPaste(MyFormat) Then
RichTextBox1.Paste(MyFormat)
PasteMyBitmap = True
Else
MessageBox.Show("The data format that you attempted to paste is not supported by this control.")
PasteMyBitmap = False
End If
End Function
Hinweise
Mit dieser Methode können Sie Daten aus der Zwischenablage in das Steuerelement einfügen. Diese Version der Methode unterscheidet sich von der PasteTextBoxBase.Paste Methode, da Sie nur Text in ein angegebenes Zwischenablageformat einfügen können. Mit der CanPaste Methode können Sie ermitteln, ob sich die Daten in der Zwischenablage im angegebenen Zwischenablageformat befinden. Anschließend können Sie diese Version der Paste Methode aufrufen, um sicherzustellen, dass der Einfügevorgang mit dem entsprechenden Datenformat erfolgt.