RichTextBox.Paste(DataFormats+Format) Metod

Definition

Klistrar in innehållet i Urklipp i det angivna Urklippsformatet.

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)

Parametrar

clipFormat
DataFormats.Format

Urklippsformatet där data ska hämtas från Urklipp.

Exempel

I följande kodexempel visas hur du använder Paste metoden för att klistra in en bitmapp i RichTextBox kontrollen. När du har öppnat en bitmapp från filen använder exemplet metoden SetDataObject för att kopiera bitmappen till Windows Urklipp. Slutligen hämtar exemplet formatet för Bitmap objektet, verifierar att formatet kan klistras in i RichTextBox kontrollen och använder Paste metoden för att klistra in data.

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

Kommentarer

Du kan använda den här metoden för att klistra in data från Urklipp i kontrollen. Den här versionen av Paste metoden skiljer sig från TextBoxBase.Paste metoden eftersom du endast kan klistra in text i ett angivet Urklippsformat. Du kan använda CanPaste metoden för att avgöra om data i Urklipp har det angivna Urklippsformatet. Du kan sedan anropa den Paste här versionen av metoden för att säkerställa att inklistringsåtgärden görs med lämpligt dataformat.

Gäller för

Se även